Opened 11 months ago

Closed 11 months ago

Last modified 11 months ago

#35104 closed Uncategorized (wontfix)

Make ModelAdmin.list_display only select proper fields

Reported by: Mounir Owned by: nobody
Component: contrib.admin Version: 5.0
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 (last modified by Tim Graham)

ModelAdmin list does always select all fields of the model.
When debugging this locally I got some issue when for example the model contain some big text fields.

A workaround of this is to use defer or only on the get_queryset to avoid the huge data to be loaded into the memory and causing the SQL request to take some time, despite explain analyse giving good results.

Would it be an option to enforce the usage of only on list_display to be the same as list_display when defined.

E.g:

class Model(models.Model)
    name = ...
    large_xml_data = ...

@admin.register(Model)
class MyModelAdmin(admin.ModelAdmin):
    list_display = ['id', 'name']

when accessing /admin/models/ this would result into a Model.objects.all().only(*MyModelAdmin.list_display).

Change History (4)

comment:1 by Tim Graham, 11 months ago

Description: modified (diff)
Resolution: wontfix
Status: newclosed

The workaround you've identified is the correct solution. We can't be too clever here since list_display can also include model methods, etc.

comment:2 by Mounir, 11 months ago

The issue that the change form will result into extra queries when accessing other fields.

What about having an explicit list_select_only or something like that?

comment:3 by Tim Graham, 11 months ago

We cannot add tiny shortcuts for every customization under the sun.

comment:4 by Mounir, 11 months ago

Clear, the admin comes with a cost anyway.

Thanks for the reply and your time.

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