From df5fef33c965ba324563c4a8a1faec82ccfbe98c Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Tue, 26 Feb 2008 21:13:16 +0000 Subject: Beefed up support for "lazy" related objects. Now, in addition to ForeignKey("Model") you can also say ForeignKey("app.Model"). This means that cross-app recursive relations now work. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7158 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/mutually_referential/models.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/modeltests/mutually_referential/models.py b/tests/modeltests/mutually_referential/models.py index 7cf7bf8bb2..5176721f3d 100644 --- a/tests/modeltests/mutually_referential/models.py +++ b/tests/modeltests/mutually_referential/models.py @@ -1,18 +1,22 @@ """ 24. Mutually referential many-to-one relationships -To define a many-to-one relationship, use ``ForeignKey()`` . +Strings can be used instead of model literals to set up "lazy" relations. """ from django.db.models import * class Parent(Model): name = CharField(max_length=100, core=True) + + # Use a simple string for forward declarations. bestchild = ForeignKey("Child", null=True, related_name="favoured_by") class Child(Model): name = CharField(max_length=100) - parent = ForeignKey(Parent) + + # You can also explicitally specify the related app. + parent = ForeignKey("mutually_referential.Parent") __test__ = {'API_TESTS':""" # Create a Parent -- cgit v1.3