From b3b8422363dd450d1ff1a376ab1f74cf2e22ce1b Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Thu, 20 Mar 2008 06:56:23 +0000 Subject: Fixed #6445 -- Allow model instances to be used as a default for ForeignKeys (via a callable). Also updates the documentation of the "default" attribute to indicate a callable can be used. Thanks, Philipe Raoult. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7331 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/model_fields/models.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/regressiontests/model_fields') diff --git a/tests/regressiontests/model_fields/models.py b/tests/regressiontests/model_fields/models.py index e69de29bb2..7e07227961 100644 --- a/tests/regressiontests/model_fields/models.py +++ b/tests/regressiontests/model_fields/models.py @@ -0,0 +1,24 @@ + +from django.db import models + +class Foo(models.Model): + a = models.CharField(max_length=10) + +def get_foo(): + return Foo.objects.get(id=1) + +class Bar(models.Model): + b = models.CharField(max_length=10) + a = models.ForeignKey(Foo, default=get_foo) + +__test__ = {'API_TESTS':""" +# Create a couple of Places. +>>> f = Foo.objects.create(a='abc') +>>> f.id +1 +>>> b = Bar(b = "bcd") +>>> b.a + +>>> b.save() + +"""} -- cgit v1.3