but the remove function is supposed to work yet it returns the error but
add works
def update(request):
product_id = request.POST.get("product_id")
    if product_id is not None :
        print(product_id)
        product_id = int(product_id)

        try:
            product_id = int(product_id)
            product_obj = Product.objects.get(id=product_id)
            #product_obj = Product.objects.get(id=product_id)
        except Product.DoesNotExist:
            print("message to user, product is gone")
            return redirect("carts:home")
        cart_obj, new_obj = Cart.objects.new_or_get(request)
        if product_obj in cart_obj.products.all():
            cart_obj.products.remove(product_obj)
            added = False

On Sat, Jun 22, 2019 at 8:18 PM Alejandro Pena <adp...@gmail.com> wrote:

> 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 error this time
> and then you see the POST and GET requests successfully completed with
> response codes 302 (return redirect to /carts) and 200 (return render...).
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/cf4d348f-9955-43f4-81b9-a4cbc98bb8b0%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMz%3Dh%3DRdP2F4sB39ad%2B-r5UQvtobBEoAAmrseW0E0aQtOgUWxg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to