Django

Code

Changeset 2610

Show
Ignore:
Timestamp:
04/04/06 14:40:00 (3 years ago)
Author:
lukeplant
Message:

magic-removal: Added an 'ordering' option on a model in order to make test deterministic across databases, and updated details of tests accordingly (fixes 7 tests on Postgres).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/magic-removal/tests/modeltests/many_to_one/models.py

    r2510 r2610  
    2323        return self.headline 
    2424 
     25    class Meta: 
     26        ordering = ('headline',) 
    2527 
    2628API_TESTS = """ 
     
    61631 
    6264>>> r.article_set.all() 
    63 [This is a test, John's second story, Paul's story
     65[John's second story, Paul's story, This is a test
    6466 
    6567# Add the same article to a different article set - check that it moves. 
     
    68702 
    6971>>> r.article_set.all() 
    70 [This is a test, John's second story
     72[John's second story, This is a test
    7173>>> r2.article_set.all() 
    7274[Paul's story] 
     
    80821 
    8183>>> r.article_set.all() 
    82 [This is a test, John's second story, Paul's story
     84[John's second story, Paul's story, This is a test
    8385>>> r2.article_set.all() 
    8486[] 
     
    9597>>> r.article_set = [new_article] 
    9698>>> r.article_set.all() 
    97 [This is a test, John's second story
     99[John's second story, This is a test
    98100>>> r2.article_set.all() 
    99101[Paul's story] 
     
    106108 
    107109# Reporter objects have access to their related Article objects. 
    108 >>> r.article_set.order_by('pub_date'
    109 [This is a test, John's second story
     110>>> r.article_set.all(
     111[John's second story, This is a test
    110112 
    111113>>> r.article_set.filter(headline__startswith='This') 
     
    132134# This works as many levels deep as you want. There's no limit. 
    133135# Find all Articles for any Reporter whose first name is "John". 
    134 >>> Article.objects.filter(reporter__first_name__exact='John').order_by('pub_date') 
    135 [This is a test, John's second story
     136>>> Article.objects.filter(reporter__first_name__exact='John') 
     137[John's second story, This is a test
    136138 
    137139# Query twice over the related field. 
    138140>>> Article.objects.filter(reporter__first_name__exact='John', reporter__last_name__exact='Smith') 
    139 [This is a test, John's second story
     141[John's second story, This is a test
    140142 
    141143# The underlying query only makes one join when a related table is referenced twice. 
     
    147149# The automatically joined table has a predictable name. 
    148150>>> Article.objects.filter(reporter__first_name__exact='John').extra(where=["many_to_one_article__reporter.last_name='Smith'"]) 
    149 [This is a test, John's second story
     151[John's second story, This is a test
    150152 
    151153# Find all Articles for the Reporter whose ID is 1. 
    152 >>> Article.objects.filter(reporter__id__exact=1).order_by('pub_date') 
    153 [This is a test, John's second story
    154 >>> Article.objects.filter(reporter__pk=1).order_by('pub_date') 
    155 [This is a test, John's second story
     154>>> Article.objects.filter(reporter__id__exact=1) 
     155[John's second story, This is a test
     156>>> Article.objects.filter(reporter__pk=1) 
     157[John's second story, This is a test
    156158 
    157159# You need two underscores between "reporter" and "id" -- not one. 
     
    168170 
    169171# "pk" shortcut syntax works in a related context, too. 
    170 >>> Article.objects.filter(reporter__pk=1).order_by('pub_date') 
    171 [This is a test, John's second story
     172>>> Article.objects.filter(reporter__pk=1) 
     173[John's second story, This is a test
    172174 
    173175# You can also instantiate an Article by passing 
     
    211213 
    212214# If you delete a reporter, his articles will be deleted. 
    213 >>> Article.objects.order_by('headline'
     215>>> Article.objects.all(
    214216[John's second story, Paul's story, This is a test, This is a test, This is a test] 
    215217>>> Reporter.objects.order_by('first_name') 
    216218[John Smith, Paul Jones] 
    217219>>> r2.delete() 
    218 >>> Article.objects.order_by('headline'
     220>>> Article.objects.all(
    219221[John's second story, This is a test, This is a test, This is a test] 
    220222>>> Reporter.objects.order_by('first_name')