[Answer]-In Django/Python is there a is_model function?

1👍

use Python built in function isinstance.

Assuming your model class is Models:

if isinstance(models, QuerySet):
    #models is a list of Models
    pass

if isinstance(models, Models):
    #models is an instance of Models
    pass

0👍

models = Models.object.all()

returns always a QuerySet. I suppose you want to know if is composed by more than 1 record.

you can check with len(models) (but this is not performance friendly) or use Models.object.count()

👤sax

Leave a comment