[Django]-Check if an object is a QuerySet

57👍

You can use python built-in function isinstance.

from django.db.models.query import QuerySet
isinstance(your_qs, QuerySet)

4👍

You can get the type of obj by python’s inbuilt type()

Try this :

  type(obj)

It will return as below if its a Queryset

  <class 'django.db.models.query.QuerySet'>

Leave a comment