﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33911	Add hook for BaseModelAdmin.raw_id_fields	Ivan Dominic Baguio	nobody	"`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.
"	New feature	closed	contrib.admin	dev	Normal	duplicate	admin		Unreviewed	0	0	0	0	0	0
