fix: extracted all web related stuff to a new app

This commit is contained in:
2024-11-23 20:46:14 +01:00
parent 66e24e48b2
commit 9608e283dd
24 changed files with 108 additions and 38 deletions
+48
View File
@@ -0,0 +1,48 @@
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 = "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()