#33911: Add hook for BaseModelAdmin.raw_id_fields
-----------------------------------------+------------------------
Reporter: ibaguio | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: dev
Severity: Normal | Keywords: admin
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-----------------------------------------+------------------------
`BaseModelAdmin.raw_id_fields` is a very feature in django admin that
prevents page timing out or crashing when a related field's table has too
many records for the default django admin dropdown widget. Alternatively,
`autocomplete_fields` has the same objective, but using a different
widget.
Currently, there exists a method hook
`BaseModelAdmin.get_autocomplete_fields(request)` which can be overridden
by child admin classes for customized logic. But there is no
`get_raw_id_fields` hook that allows us to add some logic for
`raw_id_fields`. It would be useful to have this hook also included in the
admin. Right now we are working around this by adding our custom logic to
populate the raw_id_fields in the `__init__` method instead.
We need this code to be added to the `BaseAdmin` class.
{{{
def get_raw_id_fields(self, request):
"""
Return a list of ForeignKey and/or ManyToMany fields which should use
a raw id widget.
"""
return self.raw_id_fields
}}}
--
The specific use case we have for this is we are writing a custom admin
class that automatically sets all of the related fields (FK, O2O, M2M) of
a model to `raw_id_fields` or `autocomplete_fields` so devs doesn't have
to manually configure the admin every time a new field is added / removed
to the model.
--
Ticket URL: <https://code.djangoproject.com/ticket/33911>
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/0107018285ae4cfc-b8689f04-e848-4589-a6c6-e0d8b5497d96-000000%40eu-central-1.amazonses.com.