我正在尝试自定义django-oscar模型。 (我正在使用2.0.3版)
我创建了一个单独的标签为apps
的文件夹,并在其中创建了我的应用程序。我想在Product
catalogue
模型
我的INSTALLED_APPS
如下
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.flatpages',
'oscar',
'oscar.apps.analytics',
'oscar.apps.checkout',
'oscar.apps.address',
'oscar.apps.shipping',
# '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',
'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',
'rest_framework',
'apps.catalogue'
]
和apps/catalogue/models.py
看起来像这样
from django.db import models
from oscar.apps.catalogue.abstract_models import AbstractProduct
# from oscar.apps.catalogue.models import *
class Product(AbstractProduct):
custom_tag_field = models.CharField(default="Pending", max_length=100)
from oscar.apps.catalogue.models import *
当我尝试迁移而无法解决它时,我不断收到此错误。
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/abhijit/e-commerce-wig/oscar/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/abhijit/e-commerce-wig/oscar/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/home/abhijit/e-commerce-wig/oscar/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/abhijit/e-commerce-wig/oscar/lib/python3.6/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/abhijit/e-commerce-wig/oscar/lib/python3.6/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/home/abhijit/e-commerce-wig/oscar/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/abhijit/e-commerce-wig/wigme/apps/catalogue/models.py", line 3, in <module>
from oscar.apps.catalogue.abstract_models import AbstractProduct
File "/home/abhijit/e-commerce-wig/oscar/lib/python3.6/site-packages/oscar/apps/catalogue/abstract_models.py", line 29, in <module>
BrowsableProductManager = get_class('catalogue.managers', 'BrowsableProductManager')
File "/home/abhijit/e-commerce-wig/oscar/lib/python3.6/site-packages/oscar/core/loading.py", line 31, in get_class
return get_classes(module_label, [classname], module_prefix)[0]
File "/home/abhijit/e-commerce-wig/oscar/lib/python3.6/site-packages/oscar/core/loading.py", line 41, in get_classes
return class_loader(module_label, classnames, module_prefix)
File "/home/abhijit/e-commerce-wig/oscar/lib/python3.6/site-packages/oscar/core/loading.py", line 104, in default_class_loader
app_name = _find_registered_app_name(module_label)
File "/home/abhijit/e-commerce-wig/oscar/lib/python3.6/site-packages/oscar/core/loading.py", line 189, in _find_registered_app_name
"Couldn't find an Oscar app to import %s from" % module_label)
oscar.core.exceptions.AppNotFoundError: Couldn't find an Oscar app to import catalogue.managers from
感谢您的帮助。谢谢!
答案 0 :(得分:0)
事实证明,我使用Django的startapp
命令创建了该应用程序,而没有使用oscar提供的管理命令对其进行分叉。如果我们使用startapp
命令,那么我们需要进行以下更改。
(我取代catalogue
应用)
将此行添加到应用程序的__init__.py
default_app_config = 'catalogue.apps.CatalogueConfig'
然后将apps.py
编辑为
import oscar.apps.catalogue.apps as apps
class CatalogueConfig(apps.CatalogueConfig):
name = 'catalogue'
label = 'catalogue'
verbose_name = 'Catalogue'