#33208: Allow globally defining custom (i.e. with select_related) querysets for
ModelChoiceFields/ForeignKeys
-----------------------------------+--------------------------------------
Reporter: Matthijs Kooijman | Owner: nobody
Type: New feature | Status: closed
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):
* status: new => closed
* resolution: => wontfix
* component: Uncategorized => contrib.admin
Comment:
Thanks for the report, however I don't think a new hook is necessary you
can use
[https://docs.djangoproject.com/en/stable/ref/contrib/admin/#django.contrib.admin.ModelAdmin.autocomplete_fields
ModelAdmin.autocomplete_fields] to avoid selecting all related instances
to display in the dropdown, as documented:
> ''"By default, the admin uses a select-box interface (<select>) for
those fields. Sometimes you don’t want to incur the overhead of
**selecting all the related instances** to display in the dropdown. The
Select2 input looks similar to the default input but comes with a search
feature that loads the options asynchronously. This is faster and more
user-friendly if the related model has many instances."''
For example:
{{{#!python
@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
search_fields = ['name', 'author__name']
# Register your models here.
@admin.register(BookReview)
class BookReviewAdmin(admin.ModelAdmin):
autocomplete_fields = ['book']
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33208#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/074.ca1d5c071c157e45885b0e2913f2af58%40djangoproject.com.