adamdoty / homebaker

A baked-goods, birthday-treat, tracking app I made for my wife.
3 stars 0 forks source link

[baker] edit coupon view #48

Open bbelderbos opened 2 years ago

adamdoty commented 2 years ago

moved comment to [baker] sync S3 bucket#50

adamdoty commented 2 years ago

moved comment to [baker] sync S3 bucket#50

adamdoty commented 2 years ago

moved comment to [Baker] User Approval/Rejection of Treat Requests#45

adamdoty commented 2 years ago

removed coupon detail since both the baker user and the recipient user have list representations of their coupons

adamdoty commented 2 years ago

some issues with coupon deletion still...

adamdoty commented 2 years ago

seems like it might be related to using coupon.id instead of coupon_idwhich might be in the django 4 book...

<a href="{% url "treats:coupon_delete" coupon.id %}">Delete Coupon</a> vs <a href="{% url "treats:coupon_delete" coupon_id %}">Delete Coupon</a>

I'm going to take a look in the morning

bbelderbos commented 2 years ago

Should be former, in the view you pass a coupon object to the template:

return render(request, 'coupons/coupon-detail.html', context={'coupon': coupon})

Unfortunately templates often fail silently so it would not tell you that coupon_id is not defined as regular Python would. Hence you then hit an error of a misconstructed URL.

Based on urls.py pattern:

path('delete/<int:pk>/coupon', views.coupon_edit, name='coupon_delete'),

... I would expect

<a href="{% url "treats:coupon_delete" coupon.id %}">Delete Coupon</a>

to work fine, is it not?

bbelderbos commented 2 years ago

@adamdoty confirming I can successfully delete coupons as baker.

adamdoty commented 2 years ago

@bbelderbos getting Foreign Key Constraint when I try to delete certain coupons. Tried searching, looking into what the foreign key constraint is, but just getting confused.