0

Я новичок в программировании и читая книгу наткнулся на такую ошибку:
AttributeError at
\’str\’ object has no attribute ‘_default_manager’
twviews:

from django.views.generic import TemplateView
from django.views.generic.detail import DetailView
from .models import Category, Good
from django.core.paginator import Paginator, InvalidPage

class GoodListView(TemplateView):
template_name = ‘index.html’
def get_context_data(self, **kwargs):
context = super(GoodListView, self).get_context_data(**kwargs)

page_num = self.request.GET.get(‘page’,1)
context[‘cats’] = Category.objects.order_by(‘name’)

if kwargs[‘cat_id’] == None:
context[‘category’] = Category.objects.first()
else:
context[‘category’] = Category.objects.get(pk = kwargs[‘cat_id’])

paginator = Paginator(Good.objects.filter(category = context[‘category’]).order_by(‘name’),1)

try:
context[‘goods’] = paginator.page(page_num)
except InvalidPage:
context[‘goods’] = paginator.page(1)

return context

class GoodDetailView(DetailView):
template_name = ‘good.html’
model = ‘Good’
pk_url_kwarg = ‘good_id’
def get_context_data(self, **kwargs):
context = super(GoodDetailView, self).get_context_data(**kwargs)
context[‘pn’] = self.request.GET.get(‘page’,1)
context[‘cats’] = Category.objects.order_by(‘name’)
return context

urls:

from django.urls import path
from . import views
from .twviews import GoodListView, GoodDetailView
urlpatterns = [

path(‘<int:cat_id>/’, GoodListView.as_view(), name = ‘index’),
path(‘good/<int:good_id>/’, GoodDetailView.as_view(), name = ‘good’)
]

Как решить данную проблему?


Добавить комментарий