Code

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#13976 closed (invalid)

Admin view with relations (ForeignKey or ManyToMany) does not limit number of entries in document

Reported by: yngve@… Owned by: nobody
Component: Uncategorized Version: 1.1
Severity: Keywords:
Cc: hcarvalhoalves Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When opening for view or edit a record in the admin view of a model with a ForeignKey or ManyToMany relation to another table, the view lists all entries from the other table in the dropdown/selection box, no matter how many entries there are in that table.

The result is that if the reference table contain hundreds of thousands, or millions of entries, the record cannot be viewed, or edited, in the admin view, because it tries to generate a document that may run into Gigabytes, as well as require accessing each record in that table to get information about it.

My suggestion is that the admin view should restrict the number of elements in such automatically generated dropdown/selection boxes to at most 100 elements, preferably less than 50, and provide an alternative selection mechanism if the number of elements exceeds this limit.

The admin view may not be intended for such cases, but I would suggest that it ought to be able to handle such situations gracefully.

Another area where such numbers cause problems is when deleting a record that references, or is referenced by, large numbers of records.

Attachments (0)

Change History (3)

comment:1 Changed 4 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 4 years ago by hcarvalhoalves

  • Resolution set to invalid
  • Status changed from new to closed

Part of your problem is solved by the use of the raw_id_fields attribute in the Admin class, which avoids pre-loading related data under the edit forms. Refer to the documentation:

http://docs.djangoproject.com/en/1.2/ref/contrib/admin/#raw-id-fields

The other part, involves overriding the delete confirmation template to not list related objects, thus avoid hitting the database. To change this, customize the template existent at django/contrib/admin/templates/delete_confirmation.html under you project templates directory. Again, refer to the documentation to learn how to override the admin templates:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates

This is a common question, but couldn't find a dupe, so I'm closing as invalid and keeping the instructions to hopefully help someone else coming later.

comment:3 Changed 4 years ago by yngve@…

  • Cc hcarvalhoalves added

Currently I am not using Django 1.2, as it is incompatible with the Django 1.1 generated tables I have.

In any case, it should not be necessary to manually override such cases. It is quite likely that many models in production will have tables that quickly grow to a size in which the 1.1 form of presenting the relations will become too cumbersome, and the code should automatically adapt to it.

Add Comment

Modify Ticket

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


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

 
Note: See TracTickets for help on using tickets.