feat: wishlist
This commit is contained in:
+16
-2
@@ -1,10 +1,10 @@
|
||||
from decimal import Decimal
|
||||
|
||||
from django.shortcuts import render
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
from shop.filters import ProductFilter
|
||||
from shop.models import CartItem, Product, ProductPrice
|
||||
from shop.models import CartItem, Product, ProductPrice, WishlistedProduct
|
||||
from web.mixins import FilteredQuerysetMixin, PaginatedQuerysetMixin
|
||||
from web.settings import ANONYMOUS_CART_ID_COOKIE_NAME
|
||||
from web.utils import get_or_create_cart
|
||||
@@ -75,4 +75,18 @@ def cart(request, *args, **kwargs):
|
||||
return response
|
||||
|
||||
|
||||
class WishlistButton(TemplateView):
|
||||
template_name = 'components/products/wishlist_button.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
product = get_object_or_404(Product, pk=self.kwargs.get('pk'))
|
||||
is_wishlisted = WishlistedProduct.objects.filter(user=self.request.user, product=product).exists()
|
||||
|
||||
return {
|
||||
"is_wishlisted": is_wishlisted,
|
||||
"product": product,
|
||||
}
|
||||
|
||||
|
||||
list_products = ListProducts.as_view()
|
||||
wishlist_button = WishlistButton.as_view()
|
||||
|
||||
Reference in New Issue
Block a user