无法自定义django-oscar模型

问题描述 投票:0回答:1

我正在尝试自定义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


感谢您的帮助。谢谢!!

我正在尝试自定义django-oscar模型。 (我正在使用2.0.3版)我创建了一个单独的文件夹,标记为apps,并在其中创建了我的应用。我想在目录中自定义产品模型...

django django-oscar
1个回答
0
投票

事实证明,我使用Django的startapp命令创建了该应用程序,而没有使用oscar提供的管理命令对其进行分叉。如果使用startapp命令,则需要进行以下更改。

(我超越了catalogue应用)

© www.soinside.com 2019 - 2024. All rights reserved.