django-material icon indicating copy to clipboard operation
django-material copied to clipboard

404 error when trying to add a related (FK) object

Open edvm opened this issue 11 years ago • 8 comments

In my model form i have some FK to another models, and when trying to add them in the admin, i got a 404 error. The problem seems to be at:

(firefighters-hq) [edvm@laptop material]$ grep -R '%s%s' ./*

. /admin/templates/material/fields/django_relatedfieldwidgetwrapper.html:

I have attached a screenshot, when i click '+' i got the 404 error. Unfortunatly i dont know how to fix this issue to send a pr :-\

screenshot from 2015-05-05 08 34 09

Same bug seems to happen on demo page (when clicking the '+'), screenshot attached: screenshot from 2015-05-05 08 48 39

edvm avatar May 05 '15 11:05 edvm

Yep, it's require a custom template tag to create a valid link. But seems it's not the last issue with new items creation.

kmmbvnr avatar May 05 '15 11:05 kmmbvnr

@kmmbvnr can i help you with this problem? Maybe if you can point me to some file, code or doc?

edvm avatar May 05 '15 15:05 edvm

Here is how the url created in admin widget - https://github.com/django/django/blob/master/django/contrib/admin/widgets.py#L286

Basically, this should be recreated somehow in . /admin/templates/material/fields/django_relatedfieldwidgetwrapper.htm

Unfortunatelly django does not provide convinient methods on widget to get proper url in template, so i suppose it could be implemented as new tempate tag for material_admin template tags library

kmmbvnr avatar May 06 '15 10:05 kmmbvnr

Another option is to make material/fields/django_relatedfieldwidgetwrapper.htm very simple, leave only {{ bound_field }} as content and do everything in admin/related_widget_wrapper.html

It have propery context with all required urls.

kmmbvnr avatar May 06 '15 10:05 kmmbvnr

Actually i like the second option. If all django widgets was implemented as RelatedFieldWidgetWrapper most of django-material forms handing code will go away.

Unfortunately only RelatedFieldWidgetWrapper have rendered using django template

kmmbvnr avatar May 06 '15 10:05 kmmbvnr

I have tested now and it's working. The foreign model is saving but the select is not updated with the new model just saved.

diegocmsantos avatar Feb 19 '16 12:02 diegocmsantos

Should be fixed now

kmmbvnr avatar May 21 '16 01:05 kmmbvnr