How to override Django Admin QuerySet?

Published 1 Dec, 2022

Reading time: 1 Mins

Admin is one of the powerful battery in Django. The default app that comes with admin is useful for accessing the database values. Often times customise the result shown in the lists can be achieved using the custom QuerySet methods.

Every time I make some create, update, delete on Django admin models interface I stumbled upon a way to modify the list item shown there. Is it possible to change the list item in Django admin interface? Actually, the answer is yes we can change the Admin interface.

QuerySet update

You can easily update the QuerySet by overriding get_queryset method in Django ModelAdmin.

def TaskAdmin(admin.ModelAdmin):
    def get_queryset(self, request):
        # Calling super to get the parent QuerySet
        qs = super().get_queryset(request)

        # Add your own filters here...
        return qs

Read More