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
import models
10 class Parent(models
.Model
):
11 name
= models
.CharField(max_length
=100)
13 # Use a simple string for forward declarations.
14 bestchild
= models
.ForeignKey("Child", null
=True, related_name
="favoured_by")
16 class Child(models
.Model
):
17 name
= models
.CharField(max_length
=100)
19 # You can also explicitally specify the related app.
20 parent
= models
.ForeignKey("mutually_referential.Parent")