Changeset 2366
- Timestamp:
- 02/22/06 07:14:44 (3 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/magic-removal/tests/modeltests/many_to_many/models.py
r2307 r2366 16 16 return self.title 17 17 18 class Meta: 19 ordering = ('title',) 20 18 21 class Article(models.Model): 19 22 headline = models.CharField(maxlength=100) … … 22 25 def __repr__(self): 23 26 return self.headline 27 28 class Meta: 29 ordering = ('headline',) 24 30 25 31 API_TESTS = """ … … 55 61 [The Python Journal] 56 62 >>> a2.publications.all() 57 [ The Python Journal, Science News, Science Weekly, Highlights for Children]63 [Highlights for Children, Science News, Science Weekly, The Python Journal] 58 64 59 65 # Publication objects have access to their related Article objects. 60 66 >>> p2.article_set.all() 61 67 [NASA uses Python] 62 >>> p1.article_set. order_by('headline')68 >>> p1.article_set.all() 63 69 [Django lets you build Web apps easily, NASA uses Python] 64 70 >>> Publication.objects.get(id=4).article_set.all() … … 85 91 86 92 >>> Publication.objects.filter(article__headline__startswith="NASA") 87 [ The Python Journal, Science News, Science Weekly, Highlights for Children]93 [Highlights for Children, Science News, Science Weekly, The Python Journal] 88 94 89 95 >>> Publication.objects.filter(article__id__exact=1) … … 96 102 >>> p1.delete() 97 103 >>> Publication.objects.all() 98 [ Science News, Science Weekly, Highlights for Children]104 [Highlights for Children, Science News, Science Weekly] 99 105 >>> a1 = Article.objects.get(pk=1) 100 106 >>> a1.publications.all() … … 105 111 >>> Article.objects.all() 106 112 [Django lets you build Web apps easily] 107 >>> p1.article_set. order_by('headline')113 >>> p1.article_set.all() 108 114 [Django lets you build Web apps easily] 109 115 … … 119 125 # Adding via the other end using keywords 120 126 >>> p2.article_set.add(headline='Oxygen-free diet works wonders') 121 >>> p2.article_set.all() .order_by('headline')127 >>> p2.article_set.all() 122 128 [NASA finds intelligent life on Earth, Oxygen-free diet works wonders] 123 >>> a5 = p2.article_set.all() .order_by('headline')[1]129 >>> a5 = p2.article_set.all()[1] 124 130 >>> a5.publications.all() 125 131 [Science News] … … 127 133 # Removing publication from an article: 128 134 >>> a4.publications.remove(p2) 129 >>> p2.article_set.all() .order_by('headline')135 >>> p2.article_set.all() 130 136 [Oxygen-free diet works wonders] 131 137 >>> a4.publications.all() … … 134 140 # And from the other end 135 141 >>> p2.article_set.remove(a5) 136 >>> p2.article_set. order_by('headline')142 >>> p2.article_set.all() 137 143 [] 138 144 >>> a5.publications.all() … … 143 149 >>> p2.article_set.add(a4, a5) 144 150 >>> a4.publications.add(p3) 145 >>> a4.publications. order_by('title')151 >>> a4.publications.all() 146 152 [Science News, Science Weekly] 147 153 >>> p2.article_set.clear() … … 153 159 # And you can clear from the other end 154 160 >>> p2.article_set.add(a4, a5) 155 >>> p2.article_set.all() .order_by('headline')161 >>> p2.article_set.all() 156 162 [NASA finds intelligent life on Earth, Oxygen-free diet works wonders] 157 >>> a4.publications. order_by('title')163 >>> a4.publications.all() 158 164 [Science News, Science Weekly] 159 165 >>> a4.publications.clear() 160 166 >>> a4.publications.all() 161 167 [] 162 >>> p2.article_set.all() .order_by('headline')168 >>> p2.article_set.all() 163 169 [Oxygen-free diet works wonders] 164 170 … … 175 181 [Highlights for Children, The Python Journal] 176 182 >>> Article.objects.all() 177 [Django lets you build Web apps easily, NASA finds intelligent life on Earth, Oxygen-free diet works wonders, NASA uses Python]183 [Django lets you build Web apps easily, NASA finds intelligent life on Earth, NASA uses Python, Oxygen-free diet works wonders] 178 184 >>> a2.publications.all() 179 185 [The Python Journal]
