2014-02-24 268 views
0

我有以下模型,它們依賴於django.contrib.auth.models.User訪問對象與Django中的模型的一對一關係

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

我怎樣才能得到一個誰涉及到TeacherUser對象QuerySet

回答

1
User.objects.exclude(teacher=None) 
相關問題