feat: wishlist view
This commit is contained in:
@@ -28,6 +28,32 @@ class ListProducts(TemplateView, FilteredQuerysetMixin, PaginatedQuerysetMixin):
|
||||
}
|
||||
|
||||
|
||||
class ListWishlistedProducts(
|
||||
TemplateView, FilteredQuerysetMixin, PaginatedQuerysetMixin
|
||||
):
|
||||
template_name = "web/list_products.html"
|
||||
queryset = Product.objects.filter(hidden=False).prefetch_related(
|
||||
"images",
|
||||
)
|
||||
filter_class = ProductFilter
|
||||
|
||||
def get_queryset(self):
|
||||
product_ids = WishlistedProduct.objects.filter(
|
||||
user=self.request.user
|
||||
).values_list("product", flat=True)
|
||||
return super().get_queryset().filter(pk__in=product_ids).distinct()
|
||||
|
||||
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(),
|
||||
}
|
||||
|
||||
|
||||
def cart_dropdown(request, *args, **kwargs):
|
||||
cart, created = get_or_create_cart(request)
|
||||
|
||||
@@ -91,4 +117,5 @@ class WishlistButton(TemplateView):
|
||||
|
||||
|
||||
list_products = ListProducts.as_view()
|
||||
list_wishlisted_products = ListWishlistedProducts.as_view()
|
||||
wishlist_button = WishlistButton.as_view()
|
||||
|
||||
Reference in New Issue
Block a user