I have the following models, which are dependent on 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')
...
How can I get a QuerySet
of User
objects who are related to Teacher
?
User.objects.exclude(teacher=None)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.