【发布时间】:2019-11-19 05:16:12
【问题描述】:
我正在尝试自定义 django-oscar 模型。 (我使用的是 2.0.3 版本)
我创建了一个标有apps 的单独文件夹,并在其中创建了我的应用程序。我想在catalogue中自定义Product模型
我的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
感谢您的帮助。谢谢!!
【问题讨论】:
-
请向我们展示您的分叉应用的
AppConfig和__init__.py。查看您发布的内容,您的AppConfig似乎不是OscarConfig的子类,或者未在您的 init 文件中指定为default_app_config。 -
是的@solarissmoke!这就是问题所在!它解决了我的问题。
标签: django django-oscar