Opened 14 years ago

Closed 14 years ago

Last modified 14 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: Henrique C. Alves Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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.

Change History (3)

comment:1 by anonymous, 14 years ago

comment:2 by Henrique C. Alves, 14 years ago

Resolution: invalid
Status: newclosed

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 by yngve@…, 14 years ago

Cc: Henrique C. Alves 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.

Note: See TracTickets for help on using tickets.
Back to Top