def form_valid(self, form):
shop = self.request.shop
customer = self.request.customer
product_id = self.request.POST.get('product_id')
response = {}
wishlist, created = Wishlist.objects.get_or_create(shop=shop, customer=customer, **form.cleaned_data)
response['id'] = wishlist.id
response['name'] = wishlist.name
if created and product_id:
wishlist.products.add(product_id)
response["product_id"] = product_id
response['product_name'] = wishlist.products.get(pk=product_id).name
response['created'] = created
return JsonResponse(response)
评论列表
文章目录