From 2db4b134809e162a6aa142300a1df14638eeae94 Mon Sep 17 00:00:00 2001 From: Gary Wilson Jr Date: Fri, 1 Aug 2008 23:16:59 +0000 Subject: Fixed #8070 -- Cache related objects passed to Model init as keyword arguments. Also: * Model init no longer performs a database query to refetch the related objects it is passed. * Model init now caches unsaved related objects correctly, too. (Previously, accessing the field would raise `DoesNotExist` error for `null=False` fields.) * Added tests for assigning `None` to `null=True` `ForeignKey` fields (refs #6886). git-svn-id: http://code.djangoproject.com/svn/django/trunk@8185 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/many_to_one/models.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tests/modeltests') diff --git a/tests/modeltests/many_to_one/models.py b/tests/modeltests/many_to_one/models.py index 081cffb807..2dd1226e97 100644 --- a/tests/modeltests/many_to_one/models.py +++ b/tests/modeltests/many_to_one/models.py @@ -46,8 +46,12 @@ __test__ = {'API_TESTS':""" # Article objects have access to their related Reporter objects. >>> r = a.reporter + +# These are strings instead of unicode strings because that's what was used in +# the creation of this reporter (and we haven't refreshed the data from the +# database, which always returns unicode strings). >>> r.first_name, r.last_name -(u'John', u'Smith') +('John', 'Smith') # Create an Article via the Reporter object. >>> new_article = r.article_set.create(headline="John's second story", pub_date=datetime(2005, 7, 29)) @@ -176,7 +180,7 @@ False [, , ] # You can also use a queryset instead of a literal list of instances. -# The queryset must be reduced to a list of values using values(), +# The queryset must be reduced to a list of values using values(), # then converted into a query >>> Article.objects.filter(reporter__in=Reporter.objects.filter(first_name='John').values('pk').query).distinct() [, ] -- cgit v1.3