Skip to content
Tuto Django logo
Tuto Django (2022-05-25 10H (Europe/Paris)) list_select_related
Type to start searching
Tuto Django
  • Index
  • Awsome Django
  • Tuto HTMX
  • Tuto HTTP
  • Tuto devops
  • Django performances
  • related + prefetch class
Tuto Django
  • Django news
  • News
  • Django architecture
  • DEPs
  • Installation
  • Doc
  • Django people
  • Community
  • Django performances
    • related + prefetch class
      • class Prefetch(lookup, queryset=None, to_attr=None)
      • prefetch_related
      • select_related
      • list_select_related
        • list_select_related
          • Django documentation
        • Show Source
        • Django documentation
      • Django select_related and prefetch_related articles
    • Django performance tools
    • Performance articles
  • Tests
  • Django tips
  • Tools
  • Django versions
  • Versions
  • Meta informations
  • Meta doc
  • list_select_related
    • Django documentation
  • Show Source

list_select_related ¶

Django documentation ¶

  • https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_select_related

Set list_select_related to tell Django to use select_related() in retrieving the list of objects on the admin change list page. This can save you a bunch of database queries.

The value should be either a boolean, a list or a tuple. Default is False.

When value is True, select_related() will always be called. When value is set to False, Django will look at list_display and call select_related() if any ForeignKey is present.

If you need more fine-grained control, use a tuple (or list) as value for list_select_related. Empty tuple will prevent Django from calling select_related at all. Any other tuple will be passed directly to select_related as parameters. For example:

class ArticleAdmin(admin.ModelAdmin):

list_select_related = (‘author’, ‘category’)

will call select_related(‘author’, ‘category’).

If you need to specify a dynamic value based on the request, you can implement a get_list_select_related() method.

Previous select_related
Next Django select_related and prefetch_related articles
© Copyright 2018-2022, DevOps people Built with sphinx 4.5.0 Python 3.10.4.
Last updated on May 25, 2022.
Created using Sphinx 4.5.0. and Material for Sphinx