我有以下模型,这些模型取决于django.contrib.auth.models.User
。
from django.db import models
from django.contrib.auth.models import User
class Teacher(models.Model):
user = models.OneToOneField(User, related_name='teacher')
...
class Student(models.Model):
user = models.OneToOneField(User, related_name='student')
...
如何获得与QuerySet
相关的User
Teacher
个对象?
答案 0 :(得分:1)
User.objects.exclude(teacher=None)