I have empty queryset of model Student
students = Students.objects.all()
If the above queryset is empty, then how can i get the mo
To get the model name from queryset
queryset.__dict__['model'].__name__
You can do:
students.model.__name__
>>> `Students`
students.model
Querysets have a model
attribute that can be used to retrieve the model they are associated with.
>>> students = Students.objects.all()
# The queryset's model class:
>>> students.model
project.app.models.Student
# Name of the model class:
>>> students.model.__name__
'Student'
# Import path of the models module:
>>> students.model.__module__
'project.app.models'
# Django app name:
>>> students.model._meta.app_label
'app'