Opened 13 years ago
Closed 13 years ago
#17951 closed New feature (wontfix)
Limit items in ModelChoiceField by default
Reported by: | Dan Poirier | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I suggest that above some default number of items, a ModelChoiceField should automatically switch to raw_id_fields mode. There could be a new parameter to change or remove the limit.
I've seen a couple of instances lately where a new Django admin page mysteriously would not load, with CPU pegged, and it turned out the model being admin'ed had a ForeignKey to a table with millions of entries, which turned into a ModelChoiceField in the admin that tried to build a widget with millions of items... it didn't work very well. This was the default behavior, not a result of deliberately choosing to create a ModelChoiceField on that big table.
Thank you for the suggestion. However, this would be a little too magical and it would also not necessarily be appropriate for every use case anyway. It is better for the developer to explicitly change the widgets explicitly where needed, and there already are some hooks to do that (e.g.
ModelAdmin.formfield_for_dbfield()
).