Try this instead:
cart_obj, new_obj = Cart.objects.get_or_create(user=request.user)
You originally had:
cart_obj, new_obj = Cart.objects.new_or_get(request)
There is no .new_or_get method in the Django QuerySet API:
https://docs.djangoproject.com/en/dev/ref/models/querysets/#get-or-create
Als
Which error are you seeing now? Try making this change and let us know what the
results are.
cart_obj, new_obj = Cart.objects.get(user=request.user)
if product_obj in cart_obj.products.all():
cart_obj.products.remove(product_obj)
added = False
Context:
ht
Sweet, looks like your code is working!
You’re still seeing the ‘2’ and that the type of product_id is a string because
your print statements are placed before you convert product_id into an int and
then use it to search for product_obj.
The evidence that it’s working is that it didn’t raise an
I feel you, figuring out such errors for the first time can be infinitely
frustrating.
I believe that the form is sending you product id numbers as strings, or 1 as
‘1’.
If the product_id = ‘1’ then product_id is not None.
However, you have defined product_id in the model for Product as an in
4 matches
Mail list logo