[Django] #35104: Make ModelAdmin.list_display only select proper fields

16 views
Skip to first unread message

Django

unread,
Jan 11, 2024, 10:30:42 AM1/11/24
to django-...@googlegroups.com
#35104: Make ModelAdmin.list_display only select proper fields
-----------------------------------------+------------------------
Reporter: Mounir | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admin | Version: 5.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
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)

--
Ticket URL: <https://code.djangoproject.com/ticket/35104>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 11, 2024, 11:01:46 AM1/11/24
to django-...@googlegroups.com
#35104: Make ModelAdmin.list_display only select proper fields
-------------------------------+--------------------------------------
Reporter: Mounir | Owner: nobody
Type: Uncategorized | Status: closed
Component: contrib.admin | Version: 5.0
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => wontfix


Old description:

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

New description:

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:
{{{#!python


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

--

Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/35104#comment:1>

Django

unread,
Jan 11, 2024, 11:06:28 AM1/11/24
to django-...@googlegroups.com
#35104: Make ModelAdmin.list_display only select proper fields
-------------------------------+--------------------------------------
Reporter: Mounir | Owner: nobody
Type: Uncategorized | Status: closed
Component: contrib.admin | Version: 5.0
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Mounir):

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?

--
Ticket URL: <https://code.djangoproject.com/ticket/35104#comment:2>

Django

unread,
Jan 11, 2024, 11:38:24 AM1/11/24
to django-...@googlegroups.com
#35104: Make ModelAdmin.list_display only select proper fields
-------------------------------+--------------------------------------
Reporter: Mounir | Owner: nobody
Type: Uncategorized | Status: closed
Component: contrib.admin | Version: 5.0
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Tim Graham):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/35104#comment:3>

Django

unread,
Jan 11, 2024, 11:48:26 AM1/11/24
to django-...@googlegroups.com
#35104: Make ModelAdmin.list_display only select proper fields
-------------------------------+--------------------------------------
Reporter: Mounir | Owner: nobody
Type: Uncategorized | Status: closed
Component: contrib.admin | Version: 5.0
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Mounir):

Clear, the admin comes with a cost anyway.

Thanks for the reply and your time.

--
Ticket URL: <https://code.djangoproject.com/ticket/35104#comment:4>

Reply all
Reply to author
Forward
0 new messages