TabularInlineAdmin queries waaaaaayyyyyy too much.

46 views
Skip to first unread message

Mark Jones

unread,
Feb 2, 2023, 10:23:40 AM2/2/23
to Django users
I have an admin with 1 row in the tabular inline.  I have a custom queryset in

class ExtensionTabularInlineFormSet(BaseInlineFormSet):
    def get_queryset(self) -> QuerySet[Extension]:
        qs = super().get_queryset()

This gets called 20 times to display that one row.  When you have more rows, it gets called 20 times/row.

The culprit is calls to this method:
def initial_form_count(self):
    """Return the number of forms that are required in this FormSet."""
    if not self.is_bound:
        return len(self.get_queryset())
    return super().initial_form_count()

The solution would be to cache this value, but admin views seem like singletons way too often for this to work.  Anyone else seen this?

Chetan Ganji

unread,
Feb 13, 2023, 4:28:46 AM2/13/23
to django...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f4bacbd9-b519-45af-8e5b-826c4b5d9c88n%40googlegroups.com.

Ryan Nowakowski

unread,
Feb 13, 2023, 9:57:18 AM2/13/23
to django...@googlegroups.com
It looks like the default implementation caches the query set:

https://github.com/django/django/blob/main/django/forms/models.py#L736
Reply all
Reply to author
Forward
0 new messages