Django

Code

Changeset 3075

Show
Ignore:
Timestamp:
06/03/06 19:23:51 (2 years ago)
Author:
adrian
Message:

Changed all model unit tests to use str() instead of repr(). Also slightly changed related-object DoesNotExist? exception message to use repr instead of str

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/fields/related.py

    r2850 r3075  
    199199                            obj.save() 
    200200                        else: 
    201                             raise rel_field.rel.to.DoesNotExist, "'%s' is not related to '%s'." % (obj, instance) 
     201                            raise rel_field.rel.to.DoesNotExist, "%r is not related to %r." % (obj, instance) 
    202202                remove.alters_data = True 
    203203 
     
    713713        self.filter_interface = filter_interface 
    714714        if limit_choices_to is None: 
    715             limit_choices_to = {}         
     715            limit_choices_to = {} 
    716716        self.limit_choices_to = limit_choices_to 
    717717        self.edit_inline = False 
  • django/trunk/tests/modeltests/basic/models.py

    r2992 r3075  
    1010    headline = models.CharField(maxlength=100, default='Default headline') 
    1111    pub_date = models.DateTimeField() 
    12      
    13     def __repr__(self): 
     12 
     13    def __str__(self): 
    1414        return self.headline 
     15 
    1516API_TESTS = """ 
    1617 
     
    4041>>> a.save() 
    4142 
    42 # Article.objects.all() returns all the articles in the database.  
     43# Article.objects.all() returns all the articles in the database. 
    4344>>> Article.objects.all() 
    44 [Area woman programs in Python
     45[<Article: Area woman programs in Python>
    4546 
    4647# Django provides a rich database lookup API. 
    4748>>> Article.objects.get(id__exact=1) 
    48 Area woman programs in Python 
     49<Article: Area woman programs in Python> 
    4950>>> Article.objects.get(headline__startswith='Area woman') 
    50 Area woman programs in Python 
     51<Article: Area woman programs in Python> 
    5152>>> Article.objects.get(pub_date__year=2005) 
    52 Area woman programs in Python 
     53<Article: Area woman programs in Python> 
    5354>>> Article.objects.get(pub_date__year=2005, pub_date__month=7) 
    54 Area woman programs in Python 
     55<Article: Area woman programs in Python> 
    5556>>> Article.objects.get(pub_date__year=2005, pub_date__month=7, pub_date__day=28) 
    56 Area woman programs in Python 
     57<Article: Area woman programs in Python> 
    5758 
    5859# The "__exact" lookup type can be omitted, as a shortcut. 
    5960>>> Article.objects.get(id=1) 
    60 Area woman programs in Python 
     61<Article: Area woman programs in Python> 
    6162>>> Article.objects.get(headline='Area woman programs in Python') 
    62 Area woman programs in Python 
     63<Article: Area woman programs in Python> 
    6364 
    6465>>> Article.objects.filter(pub_date__year=2005) 
    65 [Area woman programs in Python
     66[<Article: Area woman programs in Python>
    6667>>> Article.objects.filter(pub_date__year=2004) 
    6768[] 
    6869>>> Article.objects.filter(pub_date__year=2005, pub_date__month=7) 
    69 [Area woman programs in Python
     70[<Article: Area woman programs in Python>
    7071 
    7172# Django raises an Article.DoesNotExist exception for get() if the parameters 
     
    8586# The following is identical to articles.get(id=1). 
    8687>>> Article.objects.get(pk=1) 
    87 Area woman programs in Python 
     88<Article: Area woman programs in Python> 
    8889 
    8990# Model instances of the same type and same ID are considered equal. 
     
    223224>>> s2 = Article.objects.filter(id__exact=2) 
    224225>>> s1 | s2 
    225 [Area woman programs in Python, Second article
     226[<Article: Area woman programs in Python>, <Article: Second article>
    226227>>> s1 & s2 
    227228[] 
     
    233234# You can get items using index and slice notation. 
    234235>>> Article.objects.all()[0] 
    235 Area woman programs in Python 
     236<Article: Area woman programs in Python> 
    236237>>> Article.objects.all()[1:3] 
    237 [Second article, Third article
     238[<Article: Second article>, <Article: Third article>
    238239>>> s3 = Article.objects.filter(id__exact=3) 
    239240>>> (s1 | s2 | s3)[::2] 
    240 [Area woman programs in Python, Third article
     241[<Article: Area woman programs in Python>, <Article: Third article>
    241242 
    242243# Slices (without step) are lazy: 
    243244>>> Article.objects.all()[0:5].filter() 
    244 [Area woman programs in Python, Second article, Third article, Fourth article, Article 6
     245[<Article: Area woman programs in Python>, <Article: Second article>, <Article: Third article>, <Article: Fourth article>, <Article: Article 6>
    245246 
    246247# Slicing again works: 
    247248>>> Article.objects.all()[0:5][0:2] 
    248 [Area woman programs in Python, Second article
     249[<Article: Area woman programs in Python>, <Article: Second article>
    249250>>> Article.objects.all()[0:5][:2] 
    250 [Area woman programs in Python, Second article
     251[<Article: Area woman programs in Python>, <Article: Second article>
    251252>>> Article.objects.all()[0:5][4:] 
    252 [Article 6
     253[<Article: Article 6>
    253254>>> Article.objects.all()[0:5][5:] 
    254255[] 
     
    256257# Some more tests! 
    257258>>> Article.objects.all()[2:][0:2] 
    258 [Third article, Fourth article
     259[<Article: Third article>, <Article: Fourth article>
    259260>>> Article.objects.all()[2:][:2] 
    260 [Third article, Fourth article
     261[<Article: Third article>, <Article: Fourth article>
    261262>>> Article.objects.all()[2:][2:3] 
    262 [Article 6
     263[<Article: Article 6>
    263264 
    264265# Note that you can't use 'offset' without 'limit' (on some dbs), so this doesn't work: 
     
    309310# Bulk delete test: How many objects before and after the delete? 
    310311>>> Article.objects.all() 
    311 [Area woman programs in Python, Second article, Third article, Fourth article, Article 6, Default headline, Article 7, Updated article 8
     312[<Article: Area woman programs in Python>, <Article: Second article>, <Article: Third article>, <Article: Fourth article>, <Article: Article 6>, <Article: Default headline>, <Article: Article 7>, <Article: Updated article 8>
    312313>>> Article.objects.filter(id__lte=4).delete() 
    313314>>> Article.objects.all() 
    314 [Article 6, Default headline, Article 7, Updated article 8
     315[<Article: Article 6>, <Article: Default headline>, <Article: Article 7>, <Article: Updated article 8>
    315316 
    316317""" 
  • django/trunk/tests/modeltests/choices/models.py

    r2809 r3075  
    2121    gender = models.CharField(maxlength=1, choices=GENDER_CHOICES) 
    2222 
    23     def __repr__(self): 
     23    def __str__(self): 
    2424        return self.name 
    2525 
  • django/trunk/tests/modeltests/custom_columns/models.py

    r2809 r3075  
    1313    last_name = models.CharField(maxlength=30, db_column='last') 
    1414 
    15     def __repr__(self): 
     15    def __str__(self): 
    1616        return '%s %s' % (self.first_name, self.last_name) 
    1717 
     
    2525 
    2626>>> Person.objects.all() 
    27 [John Smith
     27[<Person: John Smith>
    2828 
    2929>>> Person.objects.filter(first_name__exact='John') 
    30 [John Smith
     30[<Person: John Smith>
    3131 
    3232>>> Person.objects.get(first_name__exact='John') 
    33 John Smith 
     33<Person: John Smith> 
    3434 
    3535>>> Person.objects.filter(firstname__exact='John') 
  • django/trunk/tests/modeltests/custom_managers/models.py

    r3028 r3075  
    2424    objects = PersonManager() 
    2525 
    26     def __repr__(self): 
     26    def __str__(self): 
    2727        return "%s %s" % (self.first_name, self.last_name) 
    2828 
     
    4040    authors = models.ManyToManyField(Person, related_name='books') 
    4141 
    42     def __repr__(self): 
     42    def __str__(self): 
    4343        return self.title 
    4444 
     
    5656    fast_cars = FastCarManager() 
    5757 
    58     def __repr__(self): 
     58    def __str__(self): 
    5959        return self.name 
    6060 
     
    6565>>> p2.save() 
    6666>>> Person.objects.get_fun_people() 
    67 [Bugs Bunny
     67[<Person: Bugs Bunny>
    6868 
    6969# The RelatedManager used on the 'books' descriptor extends the default manager 
     
    9090 
    9191>>> Book.published_objects.all() 
    92 [How to program
     92[<Book: How to program>
    9393 
    9494>>> c1 = Car(name='Corvette', mileage=21, top_speed=180) 
     
    9797>>> c2.save() 
    9898>>> Car.cars.order_by('name') 
    99 [Corvette, Neon
     99[<Car: Corvette>, <Car: Neon>
    100100>>> Car.fast_cars.all() 
    101 [Corvette
     101[<Car: Corvette>
    102102 
    103103# Each model class gets a "_default_manager" attribute, which is a reference 
    104104# to the first manager defined in the class. In this case, it's "cars". 
    105105>>> Car._default_manager.order_by('name') 
    106 [Corvette, Neon
     106[<Car: Corvette>, <Car: Neon>
    107107""" 
  • django/trunk/tests/modeltests/custom_methods/models.py

    r3030 r3075  
    1212    pub_date = models.DateField() 
    1313 
    14     def __repr__(self): 
     14    def __str__(self): 
    1515        return self.headline 
    1616 
     
    1818        return self.pub_date == datetime.date.today() 
    1919 
    20     def get_articles_from_same_day_1(self): 
     20    def articles_from_same_day_1(self): 
    2121        return Article.objects.filter(pub_date=self.pub_date).exclude(id=self.id) 
    2222 
    23     def get_articles_from_same_day_2(self): 
     23    def articles_from_same_day_2(self): 
    2424        """ 
    2525        Verbose version of get_articles_from_same_day_1, which does a custom 
     
    4848>>> a.was_published_today() 
    4949False 
    50 >>> a.get_articles_from_same_day_1() 
    51 [Beatles reunite
    52 >>> a.get_articles_from_same_day_2() 
    53 [Beatles reunite
    54 >>> b.get_articles_from_same_day_1() 
    55 [Area man programs in Python
    56 >>> b.get_articles_from_same_day_2() 
    57 [Area man programs in Python
     50>>> a.articles_from_same_day_1() 
     51[<Article: Beatles reunite>
     52>>> a.articles_from_same_day_2() 
     53[<Article: Beatles reunite>
     54>>> b.articles_from_same_day_1() 
     55[<Article: Area man programs in Python>
     56>>> b.articles_from_same_day_2() 
     57[<Article: Area man programs in Python>
    5858""" 
  • django/trunk/tests/modeltests/custom_pk/models.py

    r2858 r3075  
    1515        ordering = ('last_name', 'first_name') 
    1616 
    17     def __repr__(self): 
     17    def __str__(self): 
    1818        return "%s %s" % (self.first_name, self.last_name) 
    1919 
     
    2424        verbose_name_plural = 'businesses' 
    2525 
    26     def __repr__(self): 
     26    def __str__(self): 
    2727        return self.name 
    2828 
     
    3131>>> dan.save() 
    3232>>> Employee.objects.all() 
    33 [Dan Jones
     33[<Employee: Dan Jones>
    3434 
    3535>>> fran = Employee(employee_code='XYZ456', first_name='Fran', last_name='Bones') 
    3636>>> fran.save() 
    3737>>> Employee.objects.all() 
    38 [Fran Bones, Dan Jones
     38[<Employee: Fran Bones>, <Employee: Dan Jones>
    3939 
    4040>>> Employee.objects.get(pk='ABC123') 
    41 Dan Jones 
     41<Employee: Dan Jones> 
    4242>>> Employee.objects.get(pk='XYZ456') 
    43 Fran Bones 
     43<Employee: Fran Bones> 
    4444>>> Employee.objects.get(pk='foo') 
    4545Traceback (most recent call last): 
     
    4949# Use the name of the primary key, rather than pk. 
    5050>>> Employee.objects.get(employee_code__exact='ABC123') 
    51 Dan Jones 
     51<Employee: Dan Jones> 
    5252 
    5353# Fran got married and changed her last name. 
     
    5656>>> fran.save() 
    5757>>> Employee.objects.filter(last_name__exact='Jones') 
    58 [Dan Jones, Fran Jones
     58[<Employee: Dan Jones>, <Employee: Fran Jones>
    5959>>> Employee.objects.in_bulk(['ABC123', 'XYZ456']) 
    60 {'XYZ456': Fran Jones, 'ABC123': Dan Jones
     60{'XYZ456': <Employee: Fran Jones>, 'ABC123': <Employee: Dan Jones>
    6161 
    6262>>> b = Business(name='Sears') 
     
    6464>>> b.employees.add(dan, fran) 
    6565>>> b.employees.all() 
    66 [Dan Jones, Fran Jones
     66[<Employee: Dan Jones>, <Employee: Fran Jones>
    6767>>> fran.business_set.all() 
    68 [Sears
     68[<Business: Sears>
    6969>>> Business.objects.in_bulk(['Sears']) 
    70 {'Sears': Sears
     70{'Sears': <Business: Sears>
    7171 
    7272>>> Business.objects.filter(name__exact='Sears') 
    73 [Sears
     73[<Business: Sears>
    7474>>> Business.objects.filter(pk='Sears') 
    75 [Sears
     75[<Business: Sears>
    7676 
    7777# Queries across tables, involving primary key 
    7878>>> Employee.objects.filter(business__name__exact='Sears') 
    79 [Dan Jones, Fran Jones
     79[<Employee: Dan Jones>, <Employee: Fran Jones>
    8080>>> Employee.objects.filter(business__pk='Sears') 
    81 [Dan Jones, Fran Jones
     81[<Employee: Dan Jones>, <Employee: Fran Jones>
    8282 
    8383>>> Business.objects.filter(employees__employee_code__exact='ABC123') 
    84 [Sears
     84[<Business: Sears>
    8585>>> Business.objects.filter(employees__pk='ABC123') 
    86 [Sears
     86[<Business: Sears>
    8787>>> Business.objects.filter(employees__first_name__startswith='Fran') 
    88 [Sears
     88[<Business: Sears>
    8989 
    9090""" 
  • django/trunk/tests/modeltests/get_latest/models.py

    r2858 r3075  
    1818        get_latest_by = 'pub_date' 
    1919 
    20     def __repr__(self): 
     20    def __str__(self): 
    2121        return self.headline 
    2222 
     
    2727    # Note that this model doesn't have "get_latest_by" set. 
    2828 
    29     def __repr__(self): 
     29    def __str__(self): 
    3030        return self.name 
    3131 
     
    5050# Get the latest Article. 
    5151>>> Article.objects.latest() 
    52 Article 4 
     52<Article: Article 4> 
    5353 
    5454# Get the latest Article that matches certain filters. 
    5555>>> Article.objects.filter(pub_date__lt=datetime(2005, 7, 27)).latest() 
    56 Article 1 
     56<Article: Article 1> 
    5757 
    5858# Pass a custom field name to latest() to change the field that's used to 
    5959# determine the latest object. 
    6060>>> Article.objects.latest('expire_date') 
    61 Article 1 
     61<Article: Article 1> 
    6262 
    6363>>> Article.objects.filter(pub_date__gt=datetime(2005, 7, 26)).latest('expire_date') 
    64 Article 3 
     64<Article: Article 3> 
    6565 
    6666# You can still use latest() with a model that doesn't have "get_latest_by" 
     
    7676 
    7777>>> Person.objects.latest('birthday') 
    78 Stephanie 
     78<Person: Stephanie> 
    7979""" 
  • django/trunk/tests/modeltests/lookup/models.py

    r2858 r3075  
    1313        ordering = ('-pub_date', 'headline') 
    1414 
    15     def __repr__(self): 
     15    def __str__(self): 
    1616        return self.headline 
    1717 
     
    6262# to objects. 
    6363>>> Article.objects.in_bulk([1, 2]) 
    64 {1: Article 1, 2: Article 2
     64{1: <Article: Article 1>, 2: <Article: Article 2>
    6565>>> Article.objects.in_bulk([3]) 
    66 {3: Article 3
     66{3: <Article: Article 3>
    6767>>> Article.objects.in_bulk([1000]) 
    6868{} 
     
    126126# fallback check. This guarantees that no records are skipped or duplicated. 
    127127>>> a1.get_next_by_pub_date() 
    128 Article 2 
     128<Article: Article 2> 
    129129>>> a2.get_next_by_pub_date() 
    130 Article 3 
     130<Article: Article 3> 
    131131>>> a3.get_next_by_pub_date() 
    132 Article 7 
     132<Article: Article 7> 
    133133>>> a4.get_next_by_pub_date() 
    134 Article 6 
     134<Article: Article 6> 
    135135>>> a5.get_next_by_pub_date() 
    136136Traceback (most recent call last): 
     
    138138DoesNotExist: Article matching query does not exist. 
    139139>>> a6.get_next_by_pub_date() 
    140 Article 5 
     140<Article: Article 5> 
    141141>>> a7.get_next_by_pub_date() 
    142 Article 4 
     142<Article: Article 4> 
    143143 
    144144>>> a7.get_previous_by_pub_date() 
    145 Article 3 
     145<Article: Article 3> 
    146146>>> a6.get_previous_by_pub_date() 
    147 Article 4 
     147<Article: Article 4> 
    148148>>> a5.get_previous_by_pub_date() 
    149 Article 6 
     149<Article: Article 6> 
    150150>>> a4.get_previous_by_pub_date() 
    151 Article 7 
     151<Article: Article 7> 
    152152>>> a3.get_previous_by_pub_date() 
    153 Article 2 
     153<Article: Article 2> 
    154154>>> a2.get_previous_by_pub_date() 
    155 Article 1 
     155<Article: Article 1> 
    156156 
    157157# Underscores and percent signs have special meaning in the underlying 
     
    160160>>> a8.save() 
    161161>>> Article.objects.filter(headline__startswith='Article') 
    162 [Article_ with underscore, Article 5, Article 6, Article 4, Article 2, Article 3, Article 7, Article 1
     162[<Article: Article_ with underscore>, <Article: Article 5>, <Article: Article 6>, <Article: Article 4>, <Article: Article 2>, <Article: Article 3>, <Article: Article 7>, <Article: Article 1>
    163163>>> Article.objects.filter(headline__startswith='Article_') 
    164 [Article_ with underscore
     164[<Article: Article_ with underscore>
    165165>>> a9 = Article(headline='Article% with percent sign', pub_date=datetime(2005, 11, 21)) 
    166166>>> a9.save() 
    167167>>> Article.objects.filter(headline__startswith='Article') 
    168 [Article% with percent sign, Article_ with underscore, Article 5, Article 6, Article 4, Article 2, Article 3, Article 7, Article 1
     168[<Article: Article% with percent sign>, <Article: Article_ with underscore>, <Article: Article 5>, <Article: Article 6>, <Article: Article 4>, <Article: Article 2>, <Article: Article 3>, <Article: Article 7>, <Article: Article 1>
    169169>>> Article.objects.filter(headline__startswith='Article%') 
    170 [Article% with percent sign
     170[<Article: Article% with percent sign>
    171171 
    172172# exclude() is the opposite of filter() when doing lookups: 
    173173>>> Article.objects.filter(headline__contains='Article').exclude(headline__contains='with') 
    174 [Article 5, Article 6, Article 4, Article 2, Article 3, Article 7, Article 1
     174[<Article: Article 5>, <Article: Article 6>, <Article: Article 4>, <Article: Article 2>, <Article: Article 3>, <Article: Article 7>, <Article: Article 1>
    175175>>> Article.objects.exclude(headline__startswith="Article_") 
    176 [Article% with percent sign, Article 5, Article 6, Article 4, Article 2, Article 3, Article 7, Article 1
     176[<Article: Article% with percent sign>, <Article: Article 5>, <Article: Article 6>, <Article: Article 4>, <Article: Article 2>, <Article: Article 3>, <Article: Article 7>, <Article: Article 1>
    177177>>> Article.objects.exclude(headline="Article 7") 
    178 [Article% with percent sign, Article_ with underscore, Article 5, Article 6, Article 4, Article 2, Article 3, Article 1
     178[<Article: Article% with percent sign>, <Article: Article_ with underscore>, <Article: Article 5>, <Article: Article 6>, <Article: Article 4>, <Article: Article 2>, <Article: Article 3>, <Article: Article 1>
    179179""" 
  • django/trunk/tests/modeltests/m2m_intermediary/models.py

    r2809 r3075  
    1717    last_name = models.CharField(maxlength=30) 
    1818 
    19     def __repr__(self): 
     19    def __str__(self): 
    2020        return "%s %s" % (self.first_name, self.last_name) 
    2121 
     
    2424    pub_date = models.DateField() 
    2525 
    26     def __repr__(self): 
     26    def __str__(self): 
    2727        return self.headline 
    2828 
     
    3232    position = models.CharField(maxlength=100) 
    3333 
    34     def __repr__(self): 
    35         return '%r (%s)' % (self.reporter, self.position) 
     34    def __str__(self): 
     35        return '%s (%s)' % (self.reporter, self.position) 
    3636 
    3737API_TESTS = """ 
     
    5555# Play around with the API. 
    5656>>> a.writer_set.select_related().order_by('-position') 
    57 [John Smith (Main writer), Jane Doe (Contributor)
     57[<Writer: John Smith (Main writer)>, <Writer: Jane Doe (Contributor)>
    5858>>> w1.reporter 
    59 John Smith 
     59<Reporter: John Smith> 
    6060>>> w2.reporter 
    61 Jane Doe 
     61<Reporter: Jane Doe> 
    6262>>> w1.article 
    63 This is a test 
     63<Article: This is a test> 
    6464>>> w2.article 
    65 This is a test 
     65<Article: This is a test> 
    6666>>> r1.writer_set.all() 
    67 [John Smith (Main writer)
     67[<Writer: John Smith (Main writer)>
    6868""" 
  • django/trunk/tests/modeltests/m2m_multiple/models.py

    r2809 r3075  
    1515       ordering = ('name',) 
    1616 
    17     def __repr__(self): 
     17    def __str__(self): 
    1818        return self.name 
    1919 
     
    2626       ordering = ('pub_date',) 
    2727 
    28     def __repr__(self): 
     28    def __str__(self): 
    2929        return self.headline 
    3030 
     
    5252 
    5353>>> a1.primary_categories.all() 
    54 [Crime, News
     54[<Category: Crime>, <Category: News>
    5555 
    5656>>> a2.primary_categories.all() 
    57 [News, Sports
     57[<Category: News>, <Category: Sports>
    5858 
    5959>>> a1.secondary_categories.all() 
    60 [Life
     60[<Category: Life>
    6161 
    6262 
    6363>>> c1.primary_article_set.all() 
    64 [Area man runs
     64[<Article: Area man runs>
    6565>>> c1.secondary_article_set.all() 
    6666[] 
    6767>>> c2.primary_article_set.all() 
    68 [Area man steals, Area man runs
     68[<Article: Area man steals>, <Article: Area man runs>
    6969>>> c2.secondary_article_set.all() 
    7070[] 
    7171>>> c3.primary_article_set.all() 
    72 [Area man steals
     72[<Article: Area man steals>
    7373>>> c3.secondary_article_set.all() 
    7474[] 
     
    7676[] 
    7777>>> c4.secondary_article_set.all() 
    78 [Area man steals, Area man runs
     78[<Article: Area man steals>, <Article: Area man runs>
    7979""" 
  • django/trunk/tests/modeltests/m2m_recursive/models.py

    r3031 r3075  
    2020    idols = models.ManyToManyField('self', symmetrical=False, related_name='stalkers') 
    2121 
    22     def __repr__(self): 
     22    def __str__(self): 
    2323        return self.name 
    2424 
     
    4242# Who is friends with Anne? 
    4343>>> a.friends.all() 
    44 [Bill, Chuck, David
     44[<Person: Bill>, <Person: Chuck>, <Person: David>
    4545 
    4646# Who is friends with Bill? 
    4747>>> b.friends.all() 
    48 [Anne
     48[<Person: Anne>
    4949 
    5050# Who is friends with Chuck? 
    5151>>> c.friends.all() 
    52 [Anne, David
     52[<Person: Anne>, <Person: David>
    5353 
    5454# Who is friends with David? 
    5555>>> d.friends.all() 
    56 [Anne, Chuck
     56[<Person: Anne>, <Person: Chuck>
    5757 
    5858# Bill is already friends with Anne - add Anne again, but in the reverse direction 
     
    6161# Who is friends with Anne? 
    6262>>> a.friends.all() 
    63 [Bill, Chuck, David
     63[<Person: Bill>, <Person: Chuck>, <Person: David>
    6464 
    6565# Who is friends with Bill? 
    6666>>> b.friends.all() 
    67 [Anne
     67[<Person: Anne>
    6868 
    6969# Remove Anne from Bill's friends 
     
    7272# Who is friends with Anne? 
    7373>>> a.friends.all() 
    74 [Chuck, David
     74[<Person: Chuck>, <Person: David>
    7575 
    7676# Who is friends with Bill? 
     
    8888# Who is friends with Chuck? 
    8989>>> c.friends.all() 
    90 [David
     90[<Person: David>
    9191 
    9292# Who is friends with David? 
    9393>>> d.friends.all() 
    94 [Chuck
     94[<Person: Chuck>
    9595 
    9696 
     
    107107# Who are Anne's idols? 
    108108>>> a.idols.all() 
    109 [Bill, Chuck, David
     109[<Person: Bill>, <Person: Chuck>, <Person: David>
    110110 
    111111# Who is stalking Anne? 
    112112>>> a.stalkers.all() 
    113 [Bill
     113[<Person: Bill>
    114114 
    115115# Who are Bill's idols? 
    116116>>> b.idols.all() 
    117 [Anne
     117[<Person: Anne>
    118118 
    119119# Who is stalking Bill? 
    120120>>> b.stalkers.all() 
    121 [Anne
     121[<Person: Anne>
    122122 
    123123# Who are Chuck's idols? 
    124124>>> c.idols.all() 
    125 [David
     125[<Person: David>
    126126 
    127127# Who is stalking Chuck? 
    128128>>> c.stalkers.all() 
    129 [Anne
     129[<Person: Anne>
    130130 
    131131# Who are David's idols? 
     
    135135# Who is stalking David 
    136136>>> d.stalkers.all() 
    137 [Anne, Chuck
     137[<Person: Anne>, <Person: Chuck>
    138138 
    139139# Bill is already being stalked by Anne - add Anne again, but in the reverse direction 
     
    142142# Who are Anne's idols? 
    143143>>> a.idols.all() 
    144 [Bill, Chuck, David
     144[<Person: Bill>, <Person: Chuck>, <Person: David>
    145145 
    146146# Who is stalking Anne? 
    147 [Bill
     147[<Person: Bill>
    148148 
    149149# Who are Bill's idols 
    150150>>> b.idols.all() 
    151 [Anne
     151[<Person: Anne>
    152152 
    153153# Who is stalking Bill? 
    154154>>> b.stalkers.all() 
    155 [Anne
     155[<Person: Anne>
    156156 
    157157# Remove Anne from Bill's list of stalkers 
     
    160160# Who are Anne's idols? 
    161161>>> a.idols.all() 
    162 [Chuck, David
     162[<Person: Chuck>, <Person: David>
    163163 
    164164# Who is stalking Anne? 
    165165>>> a.stalkers.all() 
    166 [Bill
     166[<Person: Bill>
    167167 
    168168# Who are Bill's idols? 
    169169>>> b.idols.all() 
    170 [Anne
     170[<Person: Anne>
    171171 
    172172# Who is stalking Bill? 
     
    188188# Who is friends with David? 
    189189>>> d.stalkers.all() 
    190 [Chuck
     190[<Person: Chuck>
    191191 
    192192""" 
  • django/trunk/tests/modeltests/m2o_recursive2/models.py

    r2809 r3075  
    1515    father = models.ForeignKey('self', null=True, related_name='fathers_child_set') 
    1616 
    17     def __repr__(self): 
     17    def __str__(self): 
    1818        return self.full_name 
    1919 
     
    3030 
    3131>>> kid.mother 
    32 Jane Smith 
     32<Person: Jane Smith> 
    3333>>> kid.father 
    34 John Smith Senior 
     34<Person: John Smith Senior> 
    3535>>> dad.fathers_child_set.all() 
    36 [John Smith Junior
     36[<Person: John Smith Junior>
    3737>>> mom.mothers_child_set.all() 
    38 [John Smith Junior
     38[<Person: John Smith Junior>
    3939>>> kid.mothers_child_set.all() 
    4040[] 
  • django/trunk/tests/modeltests/m2o_recursive/models.py

    r2809 r3075  
    1717    parent = models.ForeignKey('self', null=True, related_name='child_set') 
    1818 
    19     def __repr__(self): 
     19    def __str__(self): 
    2020        return self.name 
    2121 
     
    2828 
    2929>>> r.child_set.all() 
    30 [Child category
     30[<Category: Child category>
    3131>>> r.child_set.get(name__startswith='Child') 
    32 Child category 
     32<Category: Child category> 
    3333>>> print r.parent 
    3434None 
     
    3737[] 
    3838>>> c.parent 
    39 Root category 
     39<Category: Root category> 
    4040""" 
  • django/trunk/tests/modeltests/manipulators/models.py

    r3031 r3075  
    1111    last_name = models.CharField(maxlength=30) 
    1212 
    13     def __repr__(self): 
     13    def __str__(self): 
    1414        return "%s %s" % (self.first_name, self.last_name) 
    1515 
     
    1919    release_date = models.DateField(blank=True, null=True) 
    2020 
    21     def __repr__(self): 
     21    def __str__(self): 
    2222        return self.name 
    2323 
     
    3636# Verify it worked. 
    3737>>> Musician.objects.all() 
    38 [Ella Fitzgerald
     38[<Musician: Ella Fitzgerald>
    3939>>> [m1] == list(Musician.objects.all()) 
    4040True 
     
    7070# Verify it worked. 
    7171>>> Album.objects.all() 
    72 [Ella and Basie
     72[<Album: Ella and Basie>
    7373>>> Album.objects.get().musician 
    74 Ella Fitzgerald 
     74<Musician: Ella Fitzgerald> 
    7575 
    7676# Create an Album with a release_date. 
     
    8383# Verify it worked. 
    8484>>> Album.objects.order_by('name') 
    85 [Ella and Basie, Ultimate Ella
     85[<Album: Ella and Basie>, <Album: Ultimate Ella>
    8686>>> a2 = Album.objects.get(pk=2) 
    8787>>> a2 
    88 Ultimate Ella 
     88<Album: Ultimate Ella> 
    8989>>> a2.release_date 
    9090datetime.date(2005, 2, 13) 
  • django/trunk/tests/modeltests/many_to_many/models.py

    r2902 r3075  
    1313    title = models.CharField(maxlength=30) 
    1414 
    15     def __repr__(self): 
     15    def __str__(self): 
    1616        return self.title 
    1717 
     
    2323    publications = models.ManyToManyField(Publication) 
    2424 
    25     def __repr__(self): 
     25    def __str__(self): 
    2626        return self.headline 
    2727 
     
    5959# Article objects have access to their related Publication objects. 
    6060>>> a1.publications.all() 
    61 [The Python Journal
     61[<Publication: The Python Journal>
    6262>>> a2.publications.all() 
    63 [Highlights for Children, Science News, Science Weekly, The Python Journal
     63[<Publication: Highlights for Children>, <Publication: Science News>, <Publication: Science Weekly>, <Publication: The Python Journal>
    6464 
    6565# Publication objects have access to their related Article objects. 
    6666>>> p2.article_set.all() 
    67 [NASA uses Python
     67[<Article: NASA uses Python>
    6868>>> p1.article_set.all() 
    69 [Django lets you build Web apps easily, NASA uses Python
     69[<Article: Django lets you build Web apps easily>, <Article: NASA uses Python>
    7070>>> Publication.objects.get(id=4).article_set.all() 
    71 [NASA uses Python
     71[<Article: NASA uses Python>
    7272 
    7373# We can perform kwarg queries across m2m relationships 
    7474>>> Article.objects.filter(publications__id__exact=1) 
    75 [Django lets you build Web apps easily, NASA uses Python