在django中获取空查询器的类名 [英] get class name for empty queryset in django
本文介绍了在django中获取空查询器的类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有空的queryset模型学生
students = Students.objects.all()
如果上述查询器为空,那么我如何获取模型(类名)? p>
如何获取空查询器的型号?
编辑:
如何从查询集中获取应用程序名称?
解决方案
>>>学生= Students.objects.all()
#查询器的模型类:
>>> students.model
project.app.models.Student
#模型类的名称:
>>> student.model .__ name__
'学生'
#模型模块的导入路径:
>>> student.model .__ module__
'project.app.models'
#Django应用程序名称:
>>> students.model._meta.app_label
'app'
I have empty queryset of model Student
students = Students.objects.all()
If the above queryset is empty, then how can i get the model(class name)?
How can i get the model name for empty queryset?
EDIT:
How can i get the app name from the queryset?
解决方案
>>> 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'
这篇关于在django中获取空查询器的类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文