get class name for empty queryset in django

前端 未结 4 361
梦如初夏
梦如初夏 2021-01-03 18:09

I have empty queryset of model Student

students = Students.objects.all()

If the above queryset is empty, then how can i get the mo

4条回答
  •  一生所求
    2021-01-03 18:45

    >>> 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'
    

提交回复
热议问题