feat: index and product detail view

This commit is contained in:
2024-11-21 19:51:12 +01:00
parent 2c7e51d602
commit 8783404570
13 changed files with 369 additions and 7 deletions
+40 -5
View File
@@ -1,7 +1,42 @@
from django.http.response import HttpResponse
from django.shortcuts import render
from django.views.generic import TemplateView
from django.shortcuts import get_object_or_404
from django.core.paginator import Paginator
from shop.filters import ProductFilter
from shop.models import Product
from shop.mixins import FilteredQuerysetMixin, PaginatedQuerysetMixin
# Create your views here.
def index(request, *args, **kwargs):
return HttpResponse("Hello there")
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()