mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
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
This commit is contained in:
parent
b5c5e8b4c0
commit
2db4b13480
4 changed files with 83 additions and 18 deletions
|
@ -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
|
|||
[<Article: John's second story>, <Article: Paul's story>, <Article: This is a test>]
|
||||
|
||||
# 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()
|
||||
[<Article: John's second story>, <Article: This is a test>]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue