I have the following models:
class Person(models.Model):
# fields
class Teacher(Person):
# fields
class Student(Person):
# fields
teacher = models.ForeignKey(teacher)
class Staff(Person):
# fields
class SomeModel(models.Model):
# fields
point_person = models.ForeignKey(Person)
But I want to limit my "point_person" to Teacher and Student only. How can I do this?
I would offer to implement a custom manager, probably overriding the get_queryset
.
I can see 2 solutions to get only those Parent, who have ChildA and/or ChildB.
get_queryset
of your custom manager you always check this field.get_queryset
, to actually select from ChildA and ChildB, and combine the querysets afterwards into a single queryset.