【问题标题】:Customize dashboard catalogue forms in Django Oscar doesn't work在 Django Oscar 中自定义仪表板目录表单不起作用
【发布时间】:2020-04-12 20:31:53
【问题描述】:

我遵循了 django oscar 的主要文档。 我正在尝试向名为 video_url 的产品添加一个新字段。

首先我将新字段添加到产品模型中,它运行良好。 目录/models.py

from django.db import models

from oscar.apps.catalogue.abstract_models import AbstractProduct

class Product(AbstractProduct):
    video_url = models.URLField(null=True, blank=True)

from oscar.apps.catalogue.models import *

然后我继续自定义目录仪表板,但它似乎没有改变任何东西,没有错误或任何东西。

dashboard/caralogue/forms.py

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

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

myproject/settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # 'dashboard.catalogue',

    # Oscar
    'django.contrib.sites',
    'django.contrib.flatpages',

    'oscar',
    'oscar.apps.analytics',
    'oscar.apps.checkout',
    'oscar.apps.address',
    'oscar.apps.shipping',

    # My Catalogue
    'catalogue.apps.CatalogueConfig',
    # 'oscar.apps.catalogue',
    'oscar.apps.catalogue.reviews',
    'oscar.apps.partner',
    'oscar.apps.basket',
    'oscar.apps.payment',
    'oscar.apps.offer',
    'oscar.apps.order',
    'oscar.apps.customer',
    'oscar.apps.search',
    'oscar.apps.voucher',
    'oscar.apps.wishlists',
    'oscar.apps.dashboard',
    'oscar.apps.dashboard.reports',
    'oscar.apps.dashboard.users',
    'oscar.apps.dashboard.orders',

    # My Catalogue dashboard
    'dashboard.catalogue.apps.CatalogueDashboardConfig',
    # 'oscar.apps.dashboard.catalogue',
    'oscar.apps.dashboard.offers',
    'oscar.apps.dashboard.partners',
    'oscar.apps.dashboard.pages',
    'oscar.apps.dashboard.ranges',
    'oscar.apps.dashboard.reviews',
    'oscar.apps.dashboard.vouchers',
    'oscar.apps.dashboard.communications',
    'oscar.apps.dashboard.shipping',

    # 3rd-party apps that oscar depends on
    'widget_tweaks',
    'haystack',
    'treebeard',
    'sorl.thumbnail',
    'django_tables2',
]

【问题讨论】:

    标签: django django-oscar


    【解决方案1】:

    您需要先 fork 核心仪表板应用 (oscar.apps.dashboard),然后才能 fork 它的任何子应用 (oscar.apps.dashboard.catalogue) - 这就是动态加载当前无法正常工作的原因。

    此注释已发送至 added to the documentation,但尚未发布到 readthedocs.com。

    【讨论】:

    • 但幸运的是我尝试导入 get_classs 和 get_classes 并与我合作。
    【解决方案2】:

    你的 app.py 文件必须是

       import oscar.apps.dashboard.catalogue.apps as apps
    
    
       class CatalogueDashboardConfig(apps.CatalogueDashboardConfig):
            name = 'yourappsfolder.dashboard.catalogue'
    

    【讨论】:

    • 这和我的apps.py一模一样
    • 看起来 django 没有到达代码,当我尝试添加错误的语法时,服务器继续运行而没有任何错误
    • 重启服务器。迁移并重启服务器 apache2/bin/restart
    • 不,这不是问题,更改看起来适用于 models.py 但不适用于 forms.py 或任何其他文件
    【解决方案3】:

    同时将installed_appsoscar.apps.dashboard.apps.DashboardConfig修改为yourapps.dashboard.apps.DashboardConfig

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-03
      • 2011-08-15
      • 2016-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-09
      相关资源
      最近更新 更多