Module Expr Str ImportFrom alias ClassDef bases AttributeLoad NameLoad attr body Assign NameStore Call AttributeLoad NameLoad attr keyword Num Assign NameStore Call AttributeLoad NameLoad attr Str keyword NameLoad keyword Str Assign NameStore Call AttributeLoad NameLoad attr Str keyword NameLoad keyword Str FunctionDef arguments args NameParam defaults body Return AttributeLoad NameLoad attr decorator_list decorator_list Assign NameStore Dict Str Str
N/A N/A 
12. Relating a model to another model more than once

In this example, a ``Person`` can have a ``mother`` and ``father`` -- both of
which are other ``Person`` objects.

Set ``related_name`` to designate what the reverse relationship is called.
 django.db models Person N/A N/A models Model N/A N/A full_name N/A N/A models CharField max_length 20 N/A mother N/A N/A models ForeignKey self null True related_name mothers_child_set N/A father N/A N/A models ForeignKey self null True related_name fathers_child_set __unicode__ N/A N/A self N/A N/A N/A N/A self full_name N/A N/A N/A __test__ N/A API_TESTS 
# Create two Person objects -- the mom and dad in our family.
>>> dad = Person(full_name='John Smith Senior', mother=None, father=None)
>>> dad.save()
>>> mom = Person(full_name='Jane Smith', mother=None, father=None)
>>> mom.save()

# Give mom and dad a kid.
>>> kid = Person(full_name='John Smith Junior', mother=mom, father=dad)
>>> kid.save()

>>> kid.mother
<Person: Jane Smith>
>>> kid.father
<Person: John Smith Senior>
>>> dad.fathers_child_set.all()
[<Person: John Smith Junior>]
>>> mom.mothers_child_set.all()
[<Person: John Smith Junior>]
>>> kid.mothers_child_set.all()
[]
>>> kid.fathers_child_set.all()
[]
