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.
* Attachment "0001-Add-BaseAdmin.get_raw_id_fields-hook.patch" added.
Patch that implements the requested feature
* status: new => closed
* resolution: => duplicate
* easy: 1 => 0
Comment:
Duplicate of #17881.
--
Ticket URL: <https://code.djangoproject.com/ticket/33911#comment:1>