获取django中空查询集的类名

Asi*_*sif 30 python django django-models django-views

我有模型学生的空查询集

students = Students.objects.all()
Run Code Online (Sandbox Code Playgroud)

如果上面的查询集为空,那我怎样才能获得模型(类名)?

如何获取空查询集的模型名称?

编辑:

如何从查询集中获取应用程序名称?

Jak*_*cil 46

>>> 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'
Run Code Online (Sandbox Code Playgroud)


mip*_*adi 7

students.model
Run Code Online (Sandbox Code Playgroud)

查询集具有model可用于检索与其关联的模型的属性.