/tests/modeltests/mutually_referential/models.py

https://code.google.com/p/mango-py/ · Python · 19 lines · 9 code · 5 blank · 5 comment · 0 complexity · b3aae5f0222b1f9637cfaf79a1af438f MD5 · raw file

  1. """
  2. 24. Mutually referential many-to-one relationships
  3. Strings can be used instead of model literals to set up "lazy" relations.
  4. """
  5. from django.db.models import *
  6. class Parent(Model):
  7. name = CharField(max_length=100)
  8. # Use a simple string for forward declarations.
  9. bestchild = ForeignKey("Child", null=True, related_name="favoured_by")
  10. class Child(Model):
  11. name = CharField(max_length=100)
  12. # You can also explicitally specify the related app.
  13. parent = ForeignKey("mutually_referential.Parent")