[Django] #29707: New admin autocomplete widget ignores limit_choices_to filter in referring FK definition

14 views
Skip to first unread message

Django

unread,
Aug 23, 2018, 11:36:01 PM8/23/18
to django-...@googlegroups.com
#29707: New admin autocomplete widget ignores limit_choices_to filter in referring
FK definition
------------------------------------------+--------------------------------
Reporter: David W. Lloyd | Owner: Johannes Hoppe
Type: Bug | Status: assigned
Component: contrib.admin | Version: 2.1
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 |
------------------------------------------+--------------------------------
Standard dropdowns and widgets respect limit_choices_to in ORM definition
and thus filter available choices accordingly, but the new autocomplete
widget does not, providing a counter-intuitive/inconsistent experience.

See https://code.djangoproject.com/ticket/29010#comment:15 - these two
tickets are related in the sense that a fix to this bug *may* also
introduce a means of the autocomplete widget/view interaction knowing what
the referring model is, one way or another.

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

Django

unread,
Aug 24, 2018, 3:15:16 AM8/24/18
to django-...@googlegroups.com
#29707: New admin autocomplete widget ignores limit_choices_to filter in referring
FK definition
-------------------------------------+-------------------------------------

Reporter: David W. Lloyd | Owner: Johannes
Type: | Hoppe
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* version: 2.1 => master
* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

OK, lets accept this given the previous discussion on #29010. (Joe, I'm
assuming you're happy to take this on: if not please un-assign.)

We'll re-assess #29010 after this.

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

Django

unread,
Aug 30, 2018, 10:18:04 AM8/30/18
to django-...@googlegroups.com
#29707: New admin autocomplete widget ignores limit_choices_to filter in referring
FK definition
-------------------------------------+-------------------------------------

Reporter: David W. Lloyd | Owner: Johannes
Type: | Hoppe
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by leibowitz):

I've had the same issue, and tried to fix it using proxy models (to
customise the queryset). Unfortunately modifying the field model to the
proxy is not an option, so had to use hacks to replace the widget/model,
first via formfield_for_dbfield, but that creates a bunch of issues.

Again, unfortunately the only way I found that worked was to overwrite the
widget for each field in
formfield_for_foreignkey/formfield_for_manytomany.

But again, using the proxy model causes issues, like having to create a
new model and register it through a new ModelAdmin class, which can be an
issue if this be supported within django.

Finally I found that it's possible to customise the AutocompleteJsonView,
which is fairly easy to do.

Here is a snippet of what I've done so far:
https://gist.github.com/leibowitz/7a237ea8151f2d238b19ec0da5db545c

Not sure if that's useful, but I can transform that to a patch into django
ModelAdmin and AutocompleteJsonView classes, if that's good enough.

Note that the whole widget customisation wouldn't be needed in that case,
obviously.

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

Django

unread,
May 21, 2020, 9:41:09 AM5/21/20
to django-...@googlegroups.com
#29707: New admin autocomplete widget ignores limit_choices_to filter in referring
FK definition
-------------------------------------+-------------------------------------

Reporter: David W. Lloyd | Owner: Johannes
Type: | Hoppe
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carsten Fuchs):

* cc: Carsten Fuchs (added)


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

Django

unread,
May 25, 2020, 1:20:22 AM5/25/20
to django-...@googlegroups.com
#29707: New admin autocomplete widget ignores limit_choices_to filter in referring
FK definition
-------------------------------------+-------------------------------------

Reporter: David W. Lloyd | Owner: Johannes
Type: | Hoppe
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by ehossack):

* cc: ehossack (added)


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

Django

unread,
Oct 28, 2020, 11:34:00 AM10/28/20
to django-...@googlegroups.com
#29707: New admin autocomplete widget ignores limit_choices_to filter in referring
FK definition
-------------------------------------+-------------------------------------

Reporter: David W. Lloyd | Owner: Johannes
Type: | Hoppe
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Gordon Wrigley):

* cc: Gordon Wrigley (added)


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

Django

unread,
Oct 28, 2020, 12:18:03 PM10/28/20
to django-...@googlegroups.com
#29707: New admin autocomplete widget ignores limit_choices_to filter in referring
FK definition
-------------------------------------+-------------------------------------

Reporter: David W. Lloyd | Owner: Johannes
Type: | Hoppe
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Gordon Wrigley):

Considering the case of an FK from choice to poll called my_poll. It
would've been nice if the autocomplete call was
`choice/autocomplete?field=my_poll&term=bob` instead of
`poll/autocomplete?term=bob` that would have made context based filtering
way way easier.

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

Reply all
Reply to author
Forward
0 new messages