Last active
November 27, 2020 15:14
-
-
Save adhadse/49696d5e8530e28421f0dde3993fb87a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# serverapi\view.py | |
from rest_framework.decorators import api_view | |
from django.http import JsonResponse | |
@api_view(['PUT']) | |
def updateWishlist(request): | |
data = json.loads(request.body) | |
productID = data['productID'] | |
action = data['action'] | |
print('ProductID:', productID) | |
print('Action: ', action) | |
if request.user.is_authenticated: | |
customer = request.user | |
wishList, created = Wishlist.objects.get_or_create(customer=customer) | |
if action == 'add': | |
wishList.add_item(productID) | |
return JsonResponse({'wishlistItemQuantity': wishList.get_wishlist_quantity}) | |
elif action == 'add_to_cart': | |
return JsonResponse({'cartItemQuantity': wishList.add_to_cart(productID), | |
'wishlistItemQuantity': wishList.get_wishlist_quantity}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment