/tests/modeltests/mutually_referential/models.py
Python | 19 lines | 16 code | 0 blank | 3 comment | 0 complexity | b3aae5f0222b1f9637cfaf79a1af438f MD5 | raw file
Possible License(s): BSD-3-Clause
1"""
224. Mutually referential many-to-one relationships
3
4Strings can be used instead of model literals to set up "lazy" relations.
5"""
6
7from django.db.models import *
8
9class Parent(Model):
10 name = CharField(max_length=100)
11
12 # Use a simple string for forward declarations.
13 bestchild = ForeignKey("Child", null=True, related_name="favoured_by")
14
15class Child(Model):
16 name = CharField(max_length=100)
17
18 # You can also explicitally specify the related app.
19 parent = ForeignKey("mutually_referential.Parent")