In immediate help of a long time pending request, kindly help.

47 views
Skip to first unread message

Aritra Ray

unread,
Jun 1, 2021, 8:53:32 AM6/1/21
to django...@googlegroups.com

Hello, 
This is Aritra reposting the same error. I have a problem regarding an E-commerce Django website where the cart model on the admin page is showing the items added to cart by one user to all other users as well. 
I have a Profile model and a Cart model attached below. The views.py has been attached too. Kindly comment back if anything else is needed. 
Thanks in advance.


Regards,
Aritra

Error:

2021-06-01 (4).png

Views.py

2021-06-01 (1).png2021-06-01 (5).png

Models.py 

2021-06-01 (2).png2021-06-01 (3).png

oba stephen

unread,
Jun 1, 2021, 9:08:35 AM6/1/21
to django...@googlegroups.com
Hi,

I don't think you have an error here. Although I haven't looked at the code, but from your django admin page I can see that none of those items are selected. 

If you run a query from your terminal, you would notice that the items would return as empty. 

When you create a many to many relationship in django, all objects on that related model would display this way. 

What is the difference between different carts?  The difference is, the items would be selected or highlighted in a cart they belong to. 

Regards 

Best regards

Stephen Oba

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFecadtNZeLbatpdnuC_RUDdjLjbrvZTO%2BMVD7hPuHNkN%2Bv%2BBA%40mail.gmail.com.

Aritra Ray

unread,
Jun 1, 2021, 10:06:15 AM6/1/21
to django...@googlegroups.com
Oh, okay. I was unaware of that. Although, my cart page is getting redirected back to home page. Can you spot any mistake in the provided screenshots? 
Also, can you please guide on how to redirect a function to the previously visited page? Like add-to-cart should redirect to either products page or cart page itself depending on which page the user called it from.

oba stephen

unread,
Jun 1, 2021, 10:15:44 AM6/1/21
to django...@googlegroups.com
Can I see your urls.py?

Best regards

Stephen Oba

Aritra Ray

unread,
Jun 1, 2021, 10:28:56 AM6/1/21
to django...@googlegroups.com
Sure, here's the file.

2021-06-01 (6).png

Regards, 
Aritra.

oba stephen

unread,
Jun 1, 2021, 10:58:53 AM6/1/21
to django...@googlegroups.com
You should return this if you want to redirect to cart; 

return redirect(reverse("store:cart-page", kwargs={"id": <the ID of the cart>}))

Best regards

Stephen Oba

Aritra Ray

unread,
Jun 1, 2021, 11:02:42 AM6/1/21
to django...@googlegroups.com

Joel Tanko

unread,
Jun 1, 2021, 11:53:39 AM6/1/21
to django...@googlegroups.com
If you want to show the items relative to the currently logged in user, try adding this option => limit_choices_to={'user' : 'user'}, to your items field in models.py

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
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+unsubscribe@googlegroups.com.

--
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+unsubscribe@googlegroups.com.

--
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+unsubscribe@googlegroups.com.

--
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+unsubscribe@googlegroups.com.

--
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+unsubscribe@googlegroups.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFecadtUShE1Hn_jVasfJ3sU24ctaT4YqVBHRw4T_fWn1nW08Q%40mail.gmail.com.

Aritra Ray

unread,
Jun 1, 2021, 11:57:30 AM6/1/21
to django...@googlegroups.com
Right, will try and let you know.

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

--
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...@googlegroups.com.

--
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...@googlegroups.com.

--
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...@googlegroups.com.

--
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...@googlegroups.com.

--
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...@googlegroups.com.

--
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...@googlegroups.com.

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJ4Kmg5k7HuKdEx0jO%3D3PN%3DWd36eBLeAXmJ64Y9hTBa4q%2Bj%3D7w%40mail.gmail.com.

oba stephen

unread,
Jun 1, 2021, 1:48:37 PM6/1/21
to django...@googlegroups.com

Aritra Ray

unread,
Jun 4, 2021, 3:37:09 AM6/4/21
to django...@googlegroups.com
Hello

I tried this but I'm still seeing the list of cart items. Can you tell me where I am going wrong?

Regards,
Aritra

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

--
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...@googlegroups.com.

--
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...@googlegroups.com.

--
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...@googlegroups.com.

--
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...@googlegroups.com.

--
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...@googlegroups.com.

--
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...@googlegroups.com.

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJ4Kmg5k7HuKdEx0jO%3D3PN%3DWd36eBLeAXmJ64Y9hTBa4q%2Bj%3D7w%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages