Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#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 rm_, 5 years ago

Has patch: set

WIP patch for discussion here https://github.com/django/django/pull/12937

comment:2 by Mariusz Felisiak, 5 years ago

Resolution: wontfix
Status: newclosed
Summary: Make it easier to override the RelatedFieldWidgetWrapper in adminMake 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. raw_id_fields should not be customized, IMO. If you really need to use the same mechanism you can create a custom widget (without using raw_id_fields).

Last edited 5 years ago by Mariusz Felisiak (previous) (diff)

comment:3 by rm_, 5 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 Mariusz Felisiak, 5 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 rm_, 5 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.

Last edited 5 years ago by rm_ (previous) (diff)

comment:6 by rm_, 5 years ago

Cc: rm_ added
Note: See TracTickets for help on using tickets.
Back to Top