Django

Code

Show
Ignore:
Timestamp:
08/01/08 18:16:59 (5 months ago)
Author:
gwilson
Message:

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).
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/tests/modeltests/many_to_one/models.py

    r7971 r8185  
    4747# Article objects have access to their related Reporter objects. 
    4848>>> r = a.reporter 
     49 
     50# These are strings instead of unicode strings because that's what was used in 
     51# the creation of this reporter (and we haven't refreshed the data from the 
     52# database, which always returns unicode strings). 
    4953>>> r.first_name, r.last_name 
    50 (u'John', u'Smith') 
     54('John', 'Smith') 
    5155 
    5256# Create an Article via the Reporter object. 
     
    177181 
    178182# You can also use a queryset instead of a literal list of instances. 
    179 # The queryset must be reduced to a list of values using values(),  
     183# The queryset must be reduced to a list of values using values(), 
    180184# then converted into a query 
    181185>>> Article.objects.filter(reporter__in=Reporter.objects.filter(first_name='John').values('pk').query).distinct()