▶ Watch Django Wednesdays Ecommerce Playlist ✅ Subscribe To My TH-cam Channel: bit.ly/3OBQJfN bit.ly/2IGzvOR ▶ See More At: ✅ Join My Facebook Group: Codemy.com bit.ly/2GFmOBz ▶ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt! Take 50% off with coupon code: youtube50 bit.ly/2VC9WUN ▶ Get The Code bit.ly/47xAhWJ
On first glance, I am wondering on line 45 of views.py whether you should check an 'and' condition rather than an 'or' condition before saving the two forms. I haven't tried this yet myself. In other words, should you hold off saving anything to the database if either form possibly has an error. Just curious!
Question about saving both forms at the same time when either form.is_valid( ) or shipping_form.is_valid( ) at 15 minute mark. If one form is valid and one form is not valid, won't this also save the invalid form?
@@Codemycom I tried it out and it throws an error if either is invalid. I researched further and it could be that (according to chatgpt) in the .save method it is checking if the data is valid as well, but I am not sure exactly how it does this or what the difference is between that and is_valid().
@@xStealthFire i think you can separete those if statemens. like write if form._is_valid then form.save, and below that write another if shipping_form.is_valid then shipping_form.save. that way if one form is invalid it will only save the valid one
I'm still facing the same problems as the others above! Once we get shipping_user with the user__id=request.user.id, it throws that error. So my user id is 1, and his ShippingAddress id is 3, I'm not getting it on how to relate current_user based on the ShippingAddress' id...
I think the problem resides in the fact that whenever you register a new user, unlike the profile, which is automatically assigned to a new user when registered, the shipping address is not, so if they have no shipping address when we load the update info page, it throws the error saying it doesn't exist. I will try to assign a shipping address to newly registered users as a fix for now I guess :)
Hi John, Issue with line (17min12 of the video): shipping_user = ShippingAddress.objects.get(user__id=request.user.id) Info page is not working when logged as 'user1' (although, it works when logged as 'admin') Error message: DoesNotExist at /update_info/ ShippingAddress matching query does not exist.
@@rubiknoob2780 You are right, because in your user1, you are trying to retrieve info that doesn't exist. I managed to make it work by checking if the ShippingAddress.objects.get exists, if not i created a new Shipping address instance So, I substituted shipping_user = ShippingAddress.objects.get(user__id=request.user.id) with try: shipping_user = ShippingAddress.objects.get(user__id=request.user.id) except ShippingAddress.DoesNotExist: # If it doesn't exist, create a new ShippingAddress instance shipping_user = ShippingAddress(user=request.user) shipping_user.save()
@@rubiknoob2780 The reason behind it is that in user1 the Shipping address instance is not there, so its displaying an error that there query wasnt able to find it. An Approach would be to check if the instance exists and if not then create it Substitute: shipping_user = ShippingAddress.objects.get(user__id=request.user.id) with: try: shipping_user = ShippingAddress.objects.get(user__id=request.user.id) except ShippingAddress.DoesNotExist: # If it doesn't exist, create a new ShippingAddress instance shipping_user = ShippingAddress(user=request.user) shipping_user.save()
▶ Watch Django Wednesdays Ecommerce Playlist ✅ Subscribe To My TH-cam Channel:
bit.ly/3OBQJfN bit.ly/2IGzvOR
▶ See More At: ✅ Join My Facebook Group:
Codemy.com bit.ly/2GFmOBz
▶ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt!
Take 50% off with coupon code: youtube50 bit.ly/2VC9WUN
▶ Get The Code
bit.ly/47xAhWJ
On first glance, I am wondering on line 45 of views.py whether you should check an 'and' condition rather than an 'or' condition before saving the two forms. I haven't tried this yet myself. In other words, should you hold off saving anything to the database if either form possibly has an error. Just curious!
This is fantastic!🎉
Question about saving both forms at the same time when either form.is_valid( ) or shipping_form.is_valid( ) at 15 minute mark. If one form is valid and one form is not valid, won't this also save the invalid form?
Give it a try and see :-)
@@Codemycom I tried it out and it throws an error if either is invalid. I researched further and it could be that (according to chatgpt) in the .save method it is checking if the data is valid as well, but I am not sure exactly how it does this or what the difference is between that and is_valid().
@@xStealthFire i think you can separete those if statemens. like write if form._is_valid then form.save, and below that write another if shipping_form.is_valid then shipping_form.save. that way if one form is invalid it will only save the valid one
I'm still facing the same problems as the others above! Once we get shipping_user with the user__id=request.user.id, it throws that error. So my user id is 1, and his ShippingAddress id is 3, I'm not getting it on how to relate current_user based on the ShippingAddress' id...
I think the problem resides in the fact that whenever you register a new user, unlike the profile, which is automatically assigned to a new user when registered, the shipping address is not, so if they have no shipping address when we load the update info page, it throws the error saying it doesn't exist. I will try to assign a shipping address to newly registered users as a fix for now I guess :)
We fixed this in video 33: th-cam.com/video/fY2c5OdILgI/w-d-xo.html
@@Codemycom you're the best. Imma save up and get lifetime from codemy
ive deleted the old update user and updated this route, when the website is finished im gonna send you the link as the front end is custom
You can do whatever you want.
Why we are not use country list and phone code lists
Why bother?
Hi John,
Issue with line (17min12 of the video):
shipping_user = ShippingAddress.objects.get(user__id=request.user.id)
Info page is not working when logged as 'user1'
(although, it works when logged as 'admin')
Error message:
DoesNotExist at /update_info/
ShippingAddress matching query does not exist.
watch the video to the end to find the answer
same issue,couldnt find the reason behind it
@@rubiknoob2780 You are right, because in your user1, you are trying to retrieve info that doesn't exist. I managed to make it work by checking if the ShippingAddress.objects.get exists, if not i created a new Shipping address instance
So, I substituted shipping_user = ShippingAddress.objects.get(user__id=request.user.id)
with
try:
shipping_user = ShippingAddress.objects.get(user__id=request.user.id)
except ShippingAddress.DoesNotExist:
# If it doesn't exist, create a new ShippingAddress instance
shipping_user = ShippingAddress(user=request.user)
shipping_user.save()
@@rubiknoob2780 The reason behind it is that in user1 the Shipping address instance is not there, so its displaying an error that there query wasnt able to find it.
An Approach would be to check if the instance exists and if not then create it
Substitute: shipping_user = ShippingAddress.objects.get(user__id=request.user.id)
with:
try:
shipping_user = ShippingAddress.objects.get(user__id=request.user.id)
except ShippingAddress.DoesNotExist:
# If it doesn't exist, create a new ShippingAddress instance
shipping_user = ShippingAddress(user=request.user)
shipping_user.save()
@@rubiknoob2780 Same answer, I address that exact thing at the end of the video...
thank you ❤ Do you deploy the project on the Linux server at the end?
Probably not, I have courses on doing that already
FANTASTIC VIDEO Good Sir !!!
Thanks!