Skip to content

Instantly share code, notes, and snippets.

@adhadse
Last active November 27, 2020 15:14
Show Gist options
  • Save adhadse/49696d5e8530e28421f0dde3993fb87a to your computer and use it in GitHub Desktop.
Save adhadse/49696d5e8530e28421f0dde3993fb87a to your computer and use it in GitHub Desktop.
# 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