2
24. Mutually referential many-to-one relationships
4
Strings can be used instead of model literals to set up "lazy" relations.
7
from django.db.models import *
10
name = CharField(max_length=100)
12
# Use a simple string for forward declarations.
13
bestchild = ForeignKey("Child", null=True, related_name="favoured_by")
16
name = CharField(max_length=100)
18
# You can also explicitally specify the related app.
19
parent = ForeignKey("mutually_referential.Parent")
21
__test__ = {'API_TESTS':"""
23
>>> q = Parent(name='Elizabeth')
26
# Create some children
27
>>> c = q.child_set.create(name='Charles')
28
>>> e = q.child_set.create(name='Edward')
b'\\ No newline at end of file'