Opened 2 years ago
Closed 2 years ago
#33911 closed New feature (duplicate)
Add hook for BaseModelAdmin.raw_id_fields
Reported by: | Ivan Dominic Baguio | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | admin |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.
Attachments (1)
Change History (2)
by , 2 years ago
Attachment: | 0001-Add-BaseAdmin.get_raw_id_fields-hook.patch added |
---|
comment:1 by , 2 years ago
Easy pickings: | unset |
---|---|
Resolution: | → duplicate |
Status: | new → closed |
Duplicate of #17881.
Patch that implements the requested feature