我一直关注django oscar的主要文档。 并且我正在尝试将新字段添加到名为video_url的产品中。
首先,我将新字段添加到产品模型中,并且效果很好。 catalogue / 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',
]
答案 0 :(得分:0)
您的app.py文件必须为
import oscar.apps.dashboard.catalogue.apps as apps
class CatalogueDashboardConfig(apps.CatalogueDashboardConfig):
name = 'yourappsfolder.dashboard.catalogue'
答案 1 :(得分:0)
您需要先派生核心仪表板应用程序(oscar.apps.dashboard
),然后才能派生任何子应用程序(oscar.apps.dashboard.catalogue
)-这就是当前动态加载无法正常工作的原因。
此注释为added to the documentation,但尚未在readthedocs.com上显示。
答案 2 :(得分:0)
同时将 installed_apps
oscar.apps.dashboard.apps.DashboardConfig
修改为 yourapps.dashboard.apps.DashboardConfig
。