how to limit the queryset of an inline model in django admin how to limit the queryset of an inline model in django admin python python

how to limit the queryset of an inline model in django admin


Use the get_queryset method:https://docs.djangoproject.com/en/stable/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_queryset

Should look like:

class BAdmin(admin.TabularInline):    ...    def get_queryset(self, request):        qs = super(BAdmin, self).get_queryset(request)        return qs.filter(user=request.user)