from django.shortcuts import get_object_or_404 from django.views.generic import TemplateView from shop.filters import ProductFilter from shop.models import Product from web.mixins import FilteredQuerysetMixin, PaginatedQuerysetMixin class IndexView(TemplateView): template_name = "web/index.html" def get_context_data(self, **kwargs): return { "title": "Shoppy", } class ListProducts(TemplateView, FilteredQuerysetMixin, PaginatedQuerysetMixin): template_name = "web/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 = "web/product_detail.html" def get_context_data(self, pk, slug, **kwargs): product = get_object_or_404(Product, pk=pk) return { "product": product, "title": product.name, "description": product.description, "image": product.images.first(), } index = IndexView.as_view() list_products = ListProducts.as_view() product_detail = ProductDetail.as_view()