from django.shortcuts import get_object_or_404 from django.views.generic import TemplateView from shop.filters import ProductFilter from shop.mixins import FilteredQuerysetMixin, PaginatedQuerysetMixin from shop.models import Product class IndexView(TemplateView): template_name = "shop/index.html" class ListProducts(TemplateView, FilteredQuerysetMixin, PaginatedQuerysetMixin): template_name = "shop/list_products.html" queryset = Product.objects.all() filter_class = ProductFilter def get_context_data(self, **kwargs): qs = self.get_queryset() products = self.get_paginated_queryset(qs) return { "products": products, } class ProductDetail(TemplateView): template_name = "shop/product_detail.html" def get_context_data(self, pk, **kwargs): product = get_object_or_404(Product, pk=pk) return { "product": product, } index = IndexView.as_view() list_products = ListProducts.as_view() product_detail = ProductDetail.as_view()