73👍
✅
>>> 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'
9👍
students.model
Querysets have a model
attribute that can be used to retrieve the model they are associated with.
- [Django]-What are the differences between django-tastypie and djangorestframework?
- [Django]-How to format time in django-rest-framework's serializer?
- [Django]-How do I execute raw SQL in a django migration
- [Django]-Django Model Field Default Based Off Another Field in Same Model
- [Django]-Django index page best/most common practice
- [Django]-How to show ALL keys through redis-cli?
- [Django]-Request.user returns a SimpleLazyObject, how do I "wake" it?
- [Django]-Why use Django on Google App Engine?
- [Django]-Error trying to install Postgres for python (psycopg2)
0👍
If you want a model type which is a string:
queryset.model.__name__
You can check the type:
type(queryset.model.__name__)
>>> str
And if you want models.base.ModelBase
type:
queryset.model._meta.model
You can check the type:
type(queryset.model._meta.model)
>>> django.db.models.base.ModelBase
- [Django]-Redirect to named url pattern directly from urls.py in django?
- [Django]-What is the difference between postgres and postgresql_psycopg2 as a database engine for django?
- [Django]-What is the purpose of NGINX and Gunicorn running in parallel?
Source:stackexchange.com