Answer the question
In order to leave comments, you need to log in
Paginator for detail view?
I have ListView product categories when I go to a specific DetailView catalog
In the catalog I load the products related to it through product_set.all I need to do pagination for the products
The catalog and the products of 2 different applications but they are connected. The catalog has views about the list of categories and one category, and in the products application there is one view of the product card, that is, DetailView Category
code
app_name = 'catalog'
urlpatterns = [
path('', CategoriesList.as_view(), name='categories_list'),
path('<str:slug>/', CategoryDetail.as_view(), name='category_detail'),
]
class CategoriesList(ListView):
model = Category
context_object_name = 'categories'
template_name = 'catalog/categories_list.html'
class CategoryDetail(DetailView):
model = Category
template_name = 'catalog/category_detail.html'
app_name = 'product'
urlpatterns = [
# Перенаправление в каталог
path('', RedirectView.as_view(url='/catalog/')),
path('<str:slug>/', ProductDetail.as_view(), name='detail'),
]
class ProductDetail(DetailView):
"""Карточка товара"""
model = Product
template_name = 'products/products_detail.html'
def get_context_data(self, **kwargs):
"""Добавляю представление о форме ввода комментария"""
context = super().get_context_data(**kwargs)
context['comment_form'] = CommentForm()
return context
Answer the question
In order to leave comments, you need to log in
1) Yes
1.1) It depends primarily on where your models are imported from - this is the most common reason for cyclic imports.
2) You can use the paginator directly, in much the same way as it was done in the ListView, only set it on category.product_set.all(). Of course everything is done by hand.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question