Opened 2 years ago

Closed 23 months ago

#17951 closed New feature (wontfix)

Limit items in ModelChoiceField by default

Reported by: 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


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.

Attachments (0)

Change History (1)

comment:1 Changed 23 months ago by julien

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

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()).

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.