分叉 django-oscar 视图显示错误

forking django-oscar views shows an error

我分叉了客户应用程序,以便在 http://oscar/accounts/...(example 产品中添加标签) 到 edit/show 目录视图(仪表板>目录)

我使用该视图的错误是

django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

我使用了相同方法的视图进行付款结账,但是这个遇到了错误。

# yourappsfolder.customer.apps.py
import oscar.apps.customer.apps as apps
from oscar.apps.dashboard.catalogue import apps as dapps
from django.views import generic
from django.conf.urls import url
from oscar.core.loading import get_class
from .views import ProductListView

class CustomerConfig(apps.CustomerConfig):
    name = 'yourappsfolder.customer'

    def ready(self):
        super().ready()
        self.extra_view =ProductListView

    def get_urls(self):
        urls = super().get_urls()
        urls += [
            url(r'products/',self.extra_view.as_view(),name='Products'),
        ]
        return self.post_process_urls(urls)

这是我从oscar.apps.dashboard.catalogue

复制的视图
# yourappsfolder.customer.views

from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.
from django.views import generic 

from oscar.apps.dashboard.catalogue.views import ProductListView as UserProductListView


class ProductListView(UserProductListView):

    def get_context_data(self, **kwargs):
        ctx = super().get_context_data(**kwargs)
        ctx['form'] = self.form
        ctx['productclass_form'] = self.productclass_form_class()
        return ctx

    def get_description(self, form):
        if form.is_valid() and any(form.cleaned_data.values()):
            return _('Product search results')
        return _('Products')

    def get_table(self, **kwargs):
        if 'recently_edited' in self.request.GET:
            kwargs.update(dict(orderable=False))

        table = super().get_table(**kwargs)
        table.caption = self.get_description(self.form)
        return table

    def get_table_pagination(self, table):
        return dict(per_page=20)

    def filter_queryset(self, queryset):
        """
        Apply any filters to restrict the products that appear on the list
        """
        return filter_products(queryset, self.request.user)

    def get_queryset(self):
        """
        Build the queryset for this list
        """
        queryset = Product.objects.browsable_dashboard().base_queryset()
        queryset = self.filter_queryset(queryset)
        queryset = self.apply_search(queryset)
        return queryset

    def apply_search(self, queryset):
        """
        Search through the filtered queryset.

        We must make sure that we don't return search results that the user is not allowed
        to see (see filter_queryset).
        """
        self.form = self.form_class(self.request.GET)

        if not self.form.is_valid():
            return queryset

        data = self.form.cleaned_data

        if data.get('upc'):
            # Filter the queryset by upc
            # For usability reasons, we first look at exact matches and only return
            # them if there are any. Otherwise we return all results
            # that contain the UPC.

            # Look up all matches (child products, products not allowed to access) ...
            matches_upc = Product.objects.filter(upc__iexact=data['upc'])

            # ... and use that to pick all standalone or parent products that the user is
            # allowed to access.
            qs_match = queryset.filter(
                Q(id__in=matches_upc.values('id')) | Q(id__in=matches_upc.values('parent_id')))

            if qs_match.exists():
                # If there's a direct UPC match, return just that.
                queryset = qs_match
            else:
                # No direct UPC match. Let's try the same with an icontains search.
                matches_upc = Product.objects.filter(upc__icontains=data['upc'])
                queryset = queryset.filter(
                    Q(id__in=matches_upc.values('id')) | Q(id__in=matches_upc.values('parent_id')))

        if data.get('title'):
            queryset = queryset.filter(title__icontains=data['title'])

        return queryset

您有循环导入 - 将列表视图的导入移动到应用程序配置的 ready() 方法中:

class CustomerConfig(apps.CustomerConfig):
    name = 'yourappsfolder.customer'

    def ready(self):
        super().ready()
        from .views import ProductListView
        self.extra_view =ProductListView