feat: cart

This commit is contained in:
2024-11-27 17:07:03 +01:00
parent f1b25b1fdf
commit fa1d904db5
15 changed files with 448 additions and 109 deletions
+35
View File
@@ -0,0 +1,35 @@
from django.views.generic import TemplateView
from shop.filters import ProductFilter
from shop.models import Product
from web.mixins import FilteredQuerysetMixin, PaginatedQuerysetMixin, CartMixin
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()
page = self.get_paginated_queryset(qs)
return {
"page": page,
"has_next_page": page.has_next(),
"has_previous_page": page.has_previous(),
}
class CartDropdown(TemplateView, CartMixin):
template_name = "components/cart/cart_navbar.html"
def get_context_data(self, **kwargs):
cart = self.get_cart()
return {
"cart": cart,
}
list_products = ListProducts.as_view()
cart_dropdown = CartDropdown.as_view()