Sorry for title, I do not know how else to express myself.
For example, I have this three models:
class Person(models.Model):
name = models.CharField()
class Teacher(models.Model):
person = models.ForeignKey(Person)
subject = models.CharField()
class Student(models.Model):
person = models.ForeignKey(开发者_Python百科Person)
grade = models.CharField()
How can I select all Person models that are Teachers?
Person.objects.filter(teacher__isnull=False)
# return Person who has a teacher pointing to it
精彩评论