[Django] #31610: Make it easier to override the RelatedFieldWidgetWrapper in admin

8 views
Skip to first unread message

Django

unread,
May 19, 2020, 7:10:42 AM5/19/20
to django-...@googlegroups.com
#31610: Make it easier to override the RelatedFieldWidgetWrapper in admin
------------------------------------------------+------------------------
Reporter: rm_ | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/31610>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 19, 2020, 8:20:25 AM5/19/20
to django-...@googlegroups.com
#31610: Make it easier to override the RelatedFieldWidgetWrapper in admin
-------------------------------------+-------------------------------------
Reporter: rm_ | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by rm_):

* has_patch: 0 => 1


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/31610#comment:1>

Django

unread,
May 25, 2020, 3:30:29 AM5/25/20
to django-...@googlegroups.com
#31610: Make it easier to override the RelatedFieldWidgetWrapper in admin.
-------------------------------------+-------------------------------------
Reporter: rm_ | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => closed
* resolution: => wontfix


Comment:

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`).

--
Ticket URL: <https://code.djangoproject.com/ticket/31610#comment:2>

Django

unread,
May 25, 2020, 3:43:02 AM5/25/20
to django-...@googlegroups.com
#31610: Make it easier to override the RelatedFieldWidgetWrapper in admin.
-------------------------------------+-------------------------------------
Reporter: rm_ | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by rm_):

@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 :)

--
Ticket URL: <https://code.djangoproject.com/ticket/31610#comment:3>

Django

unread,
May 25, 2020, 4:09:48 AM5/25/20
to django-...@googlegroups.com
#31610: Make it easier to override the RelatedFieldWidgetWrapper in admin.
-------------------------------------+-------------------------------------
Reporter: rm_ | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by felixxm):

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/31610#comment:4>

Django

unread,
Jun 3, 2020, 3:11:16 AM6/3/20
to django-...@googlegroups.com
#31610: Make it easier to override the RelatedFieldWidgetWrapper in admin.
-------------------------------------+-------------------------------------
Reporter: rm_ | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by rm_):

Sorr 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/31610#comment:5>

Django

unread,
Jun 3, 2020, 5:16:07 AM6/3/20
to django-...@googlegroups.com
#31610: Make it easier to override the RelatedFieldWidgetWrapper in admin.
-------------------------------------+-------------------------------------
Reporter: rm_ | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by rm_):

* cc: rm_ (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/31610#comment:6>

Reply all
Reply to author
Forward
0 new messages