Wednesday, February 1, 2023

TabularInlineAdmin queries waaaaaayyyyyy too much.

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?

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
To view this discussion on the web visit

No comments:

Post a Comment