Django-oscar在仪表板中显示字段

问题描述 投票:0回答:2
from oscar.apps.catalogue.abstract_models import AbstractProduct
from oscar.core.compat import AUTH_USER_MODEL
from django.db import models

class Product(AbstractProduct):
    seller = models.ForeignKey(
        AUTH_USER_MODEL,
        on_delete=models.CASCADE,
        null=True)

from oscar.apps.catalogue.models import *

我将此代码添加到了分叉目录模型中>我想在仪表板上显示它,Image of dashboard and dropdown box 我尝试了admin.site.register,但无法正常工作。

这是覆盖表单的代码,当我分叉并重写时,它不起作用,但是当我更改核心中的代码时,它起作用。

from oscar.apps.dashboard.catalogue.forms import ProductForm

from oscar.core.loading import get_class, get_classes, get_model
from yourappsfolder.catalogue.models import Product

class SellerField(ProductForm):

    class Meta(ProductForm.Meta):

        model =Product


        fields = [
            'title','seller', 'upc', 'description', 'is_public', 'is_discountable', 'structure']
django python-3.x django-oscar
2个回答
0
投票

您不正确地分叉了表格。调用表单类SellerField将不起作用。表单类必须与核心表单具有完全相同的名称,否则Oscar的加载程序将找不到它。像这样更改它:

from oscar.apps.dashboard.catalogue.forms import ProductForm as BaseProductForm

class ProductForm(BaseProductForm):
    class Meta(BaseProductForm.Meta):
        fields = ['title','seller', 'upc', 'description', 'is_public', 'is_discountable', 'structure']

0
投票

我有同样的问题,即使我将其更名为ProductForm,它也没有起作用。Customize dashboard catalogue forms in Django Oscar doesn't work

© www.soinside.com 2019 - 2024. All rights reserved.