Django

Code

Changeset 2254

Show
Ignore:
Timestamp:
02/03/06 17:26:16 (3 years ago)
Author:
adrian
Message:

magic-removal: Fixed some bugs in many_to_many unit tests

Files:

Legend:

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

    r2244 r2254  
    3636>>> a1.save() 
    3737 
    38 # Associate the Article with one Publication. set_publications() returns a 
    39 # boolean, representing whether any records were added or deleted. 
    40 >>> a1.set_publications([p1.id]) 
    41 True 
    42  
    43 # If we set it again, it'll return False, because the list of Publications 
    44 # hasn't changed. 
    45 >>> a1.set_publications([p1.id]) 
    46 False 
     38# Associate the Article with a Publication. 
     39>>> a1.publications.add(p1) 
    4740 
    4841# Create another Article, and set it to appear in both Publications. 
    4942>>> a2 = Article(id=None, headline='NASA uses Python') 
    5043>>> a2.save() 
    51 >>> a2.set_publications([p1.id, p2.id]) 
    52 True 
    53 >>> a2.set_publications([p1.id]) 
    54 True 
    55 >>> a2.set_publications([p1.id, p2.id, p3.id]) 
    56 True 
     44>>> a2.publications.add(p1, p2) 
     45>>> a2.publications.add(p3) 
     46 
     47# Add a Publication directly via publications.add by using keyword arguments. 
     48>>> a2.publications.add(title='Highlights for Children') 
    5749 
    5850# Article objects have access to their related Publication objects. 
     
    6052[The Python Journal] 
    6153>>> a2.publications.all() 
    62 [The Python Journal, Science News, Science Weekly
     54[The Python Journal, Science News, Science Weekly, Highlights for Children
    6355 
    6456# Publication objects have access to their related Article objects. 
     
    6759>>> p1.article_set.order_by('headline') 
    6860[Django lets you build Web apps easily, NASA uses Python] 
     61>>> Publication.objects.get(id=4).article_set.all() 
     62[NASA uses Python] 
    6963 
    7064# We can perform kwarg queries across m2m relationships 
     
    8074[NASA uses Python] 
    8175 
    82 # Reverse m2m queries (i.e., start at the table that doesn't have a ManyToManyField) 
     76# Reverse m2m queries are supported (i.e., starting at the table that doesn't 
     77# have a ManyToManyField). 
    8378>>> Publication.objects.filter(id__exact=1) 
    8479[The Python Journal] 
     
    8782 
    8883>>> Publication.objects.filter(article__headline__startswith="NASA") 
    89 [The Python Journal, Science News, Science Weekly
     84[The Python Journal, Science News, Science Weekly, Highlights for Children
    9085 
    9186>>> Publication.objects.filter(article__id__exact=1) 
     
    9893>>> p1.delete() 
    9994>>> Publication.objects.all() 
    100 [Science News, Science Weekly
     95[Science News, Science Weekly, Highlights for Children
    10196>>> a1 = Article.objects.get(pk=1) 
    10297>>> a1.publications.all()