【问题标题】:Django - oscar show a field in dashboardDjango - 奥斯卡在仪表板中显示一个字段
【发布时间】:2020-04-09 04:52:55
【问题描述】:
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']

【问题讨论】:

  • @solarissmoke 我确实分叉了它,我将代码添加到了问题中,当我编辑核心时它可以工作,但是当我分叉时它不起作用(它读取并且没有错误),应用程序是也安装在设置中并删除了#'oscar.apps.dashboard.catalogue',

标签: django python-3.x django-oscar


【解决方案1】:

您错误地分叉了表单。调用您的表单类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']

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-02
    • 1970-01-01
    • 2011-10-11
    • 2018-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    相关资源
    最近更新 更多