#31610 closed Cleanup/optimization (wontfix)
Make it easier to override the RelatedFieldWidgetWrapper in admin.
Reported by: | rm_ | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | rm_ | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
My use case is to pass some initial data to new model instances added via the add-related link. This should be trivial leveraging ModelAdmin.get_changeform_initial_data but I can't find an easy way to pass the query string to the RelatedFieldWidgetWrapper widget in order to be rendered in the template.
Possible plan:
- extract related field widget creation from BaseModelAdmin.formfield_for_dbfield into an get_widget_for_related_field helper
- create a get_url_params helper in RelatedFieldWidgetWrapper
Both looks like cleanups that have their own merit.
Change History (6)
comment:1 by , 5 years ago
Has patch: | set |
---|
comment:2 by , 4 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Summary: | Make it easier to override the RelatedFieldWidgetWrapper in admin → Make it easier to override the RelatedFieldWidgetWrapper in admin. |
Thanks for this ticket, however you use case looks quite niche, I don't see a wide use of new hooks. . If you really need to use the same mechanism you can create a custom widget (raw_id_fields
should not be customized, IMOwithout using ).raw_id_fields
comment:3 by , 4 years ago
@felixxm I'm a bit puzzled. This is has nothing to do with raw_id_fields but with the changeform popup and the related widget wrapper :) I won't object the niche use case though but what I'm doing here is making easier to override the default widget which is what you are suggesting :)
comment:4 by , 4 years ago
True, sorry, forget what I said about raw_id_fields
. Nevertheless I still think you should be able to handle this with a custom widget.
comment:5 by , 4 years ago
Sorry for the late response but I didn't get any notification. The plan is to use a custom widget, the patches here are 1) a way to use a custom widget without overriding the full BaseModelAdmin.formfield_for_dbfield becasue RelatedFieldWidgetWrapper is hardcoded 2) extract a simpler method in RelatedFieldWidgetWrapper to override (that also matches what the other related widgets are doing). Anyway I don't want to insist, thanks anyway for the review.
comment:6 by , 4 years ago
Cc: | added |
---|
WIP patch for discussion here https://github.com/django/django/pull/12937