Changeset 3075
- Timestamp:
- 06/03/06 19:23:51 (2 years ago)
- Files:
-
- django/trunk/django/db/models/fields/related.py (modified) (2 diffs)
- django/trunk/tests/modeltests/basic/models.py (modified) (7 diffs)
- django/trunk/tests/modeltests/choices/models.py (modified) (1 diff)
- django/trunk/tests/modeltests/custom_columns/models.py (modified) (2 diffs)
- django/trunk/tests/modeltests/custom_managers/models.py (modified) (6 diffs)
- django/trunk/tests/modeltests/custom_methods/models.py (modified) (3 diffs)
- django/trunk/tests/modeltests/custom_pk/models.py (modified) (6 diffs)
- django/trunk/tests/modeltests/get_latest/models.py (modified) (4 diffs)
- django/trunk/tests/modeltests/lookup/models.py (modified) (5 diffs)
- django/trunk/tests/modeltests/m2m_intermediary/models.py (modified) (4 diffs)
- django/trunk/tests/modeltests/m2m_multiple/models.py (modified) (4 diffs)
- django/trunk/tests/modeltests/m2m_recursive/models.py (modified) (10 diffs)
- django/trunk/tests/modeltests/m2o_recursive2/models.py (modified) (2 diffs)
- django/trunk/tests/modeltests/m2o_recursive/models.py (modified) (3 diffs)
- django/trunk/tests/modeltests/manipulators/models.py (modified) (5 diffs)
- django/trunk/tests/modeltests/many_to_many/models.py (modified) (10 diffs)
- django/trunk/tests/modeltests/many_to_one/models.py (modified) (16 diffs)
- django/trunk/tests/modeltests/many_to_one_null/models.py (modified) (10 diffs)
- django/trunk/tests/modeltests/model_inheritance/models.py (modified) (3 diffs)
- django/trunk/tests/modeltests/one_to_one/models.py (modified) (6 diffs)
- django/trunk/tests/modeltests/ordering/models.py (modified) (2 diffs)
- django/trunk/tests/modeltests/or_lookups/models.py (modified) (5 diffs)
- django/trunk/tests/modeltests/pagination/models.py (modified) (2 diffs)
- django/trunk/tests/modeltests/reserved_names/models.py (modified) (4 diffs)
- django/trunk/tests/modeltests/reverse_lookup/models.py (modified) (4 diffs)
- django/trunk/tests/modeltests/save_delete_hooks/models.py (modified) (2 diffs)
- django/trunk/tests/modeltests/transactions/models.py (modified) (6 diffs)
- django/trunk/tests/modeltests/validation/models.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/db/models/fields/related.py
r2850 r3075 199 199 obj.save() 200 200 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) 202 202 remove.alters_data = True 203 203 … … 713 713 self.filter_interface = filter_interface 714 714 if limit_choices_to is None: 715 limit_choices_to = {} 715 limit_choices_to = {} 716 716 self.limit_choices_to = limit_choices_to 717 717 self.edit_inline = False django/trunk/tests/modeltests/basic/models.py
r2992 r3075 10 10 headline = models.CharField(maxlength=100, default='Default headline') 11 11 pub_date = models.DateTimeField() 12 13 def __ repr__(self):12 13 def __str__(self): 14 14 return self.headline 15 15 16 API_TESTS = """ 16 17 … … 40 41 >>> a.save() 41 42 42 # Article.objects.all() returns all the articles in the database. 43 # Article.objects.all() returns all the articles in the database. 43 44 >>> Article.objects.all() 44 [ Area woman programs in Python]45 [<Article: Area woman programs in Python>] 45 46 46 47 # Django provides a rich database lookup API. 47 48 >>> Article.objects.get(id__exact=1) 48 Area woman programs in Python 49 <Article: Area woman programs in Python> 49 50 >>> Article.objects.get(headline__startswith='Area woman') 50 Area woman programs in Python 51 <Article: Area woman programs in Python> 51 52 >>> Article.objects.get(pub_date__year=2005) 52 Area woman programs in Python 53 <Article: Area woman programs in Python> 53 54 >>> Article.objects.get(pub_date__year=2005, pub_date__month=7) 54 Area woman programs in Python 55 <Article: Area woman programs in Python> 55 56 >>> 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> 57 58 58 59 # The "__exact" lookup type can be omitted, as a shortcut. 59 60 >>> Article.objects.get(id=1) 60 Area woman programs in Python 61 <Article: Area woman programs in Python> 61 62 >>> Article.objects.get(headline='Area woman programs in Python') 62 Area woman programs in Python 63 <Article: Area woman programs in Python> 63 64 64 65 >>> Article.objects.filter(pub_date__year=2005) 65 [ Area woman programs in Python]66 [<Article: Area woman programs in Python>] 66 67 >>> Article.objects.filter(pub_date__year=2004) 67 68 [] 68 69 >>> Article.objects.filter(pub_date__year=2005, pub_date__month=7) 69 [ Area woman programs in Python]70 [<Article: Area woman programs in Python>] 70 71 71 72 # Django raises an Article.DoesNotExist exception for get() if the parameters … … 85 86 # The following is identical to articles.get(id=1). 86 87 >>> Article.objects.get(pk=1) 87 Area woman programs in Python 88 <Article: Area woman programs in Python> 88 89 89 90 # Model instances of the same type and same ID are considered equal. … … 223 224 >>> s2 = Article.objects.filter(id__exact=2) 224 225 >>> s1 | s2 225 [ Area woman programs in Python, Second article]226 [<Article: Area woman programs in Python>, <Article: Second article>] 226 227 >>> s1 & s2 227 228 [] … … 233 234 # You can get items using index and slice notation. 234 235 >>> Article.objects.all()[0] 235 Area woman programs in Python 236 <Article: Area woman programs in Python> 236 237 >>> Article.objects.all()[1:3] 237 [ Second article, Third article]238 [<Article: Second article>, <Article: Third article>] 238 239 >>> s3 = Article.objects.filter(id__exact=3) 239 240 >>> (s1 | s2 | s3)[::2] 240 [ Area woman programs in Python, Third article]241 [<Article: Area woman programs in Python>, <Article: Third article>] 241 242 242 243 # Slices (without step) are lazy: 243 244 >>> 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>] 245 246 246 247 # Slicing again works: 247 248 >>> 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>] 249 250 >>> Article.objects.all()[0:5][:2] 250 [ Area woman programs in Python, Second article]251 [<Article: Area woman programs in Python>, <Article: Second article>] 251 252 >>> Article.objects.all()[0:5][4:] 252 [ Article 6]253 [<Article: Article 6>] 253 254 >>> Article.objects.all()[0:5][5:] 254 255 [] … … 256 257 # Some more tests! 257 258 >>> Article.objects.all()[2:][0:2] 258 [ Third article, Fourth article]259 [<Article: Third article>, <Article: Fourth article>] 259 260 >>> Article.objects.all()[2:][:2] 260 [ Third article, Fourth article]261 [<Article: Third article>, <Article: Fourth article>] 261 262 >>> Article.objects.all()[2:][2:3] 262 [ Article 6]263 [<Article: Article 6>] 263 264 264 265 # Note that you can't use 'offset' without 'limit' (on some dbs), so this doesn't work: … … 309 310 # Bulk delete test: How many objects before and after the delete? 310 311 >>> 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>] 312 313 >>> Article.objects.filter(id__lte=4).delete() 313 314 >>> 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>] 315 316 316 317 """ django/trunk/tests/modeltests/choices/models.py
r2809 r3075 21 21 gender = models.CharField(maxlength=1, choices=GENDER_CHOICES) 22 22 23 def __ repr__(self):23 def __str__(self): 24 24 return self.name 25 25 django/trunk/tests/modeltests/custom_columns/models.py
r2809 r3075 13 13 last_name = models.CharField(maxlength=30, db_column='last') 14 14 15 def __ repr__(self):15 def __str__(self): 16 16 return '%s %s' % (self.first_name, self.last_name) 17 17 … … 25 25 26 26 >>> Person.objects.all() 27 [ John Smith]27 [<Person: John Smith>] 28 28 29 29 >>> Person.objects.filter(first_name__exact='John') 30 [ John Smith]30 [<Person: John Smith>] 31 31 32 32 >>> Person.objects.get(first_name__exact='John') 33 John Smith 33 <Person: John Smith> 34 34 35 35 >>> Person.objects.filter(firstname__exact='John') django/trunk/tests/modeltests/custom_managers/models.py
r3028 r3075 24 24 objects = PersonManager() 25 25 26 def __ repr__(self):26 def __str__(self): 27 27 return "%s %s" % (self.first_name, self.last_name) 28 28 … … 40 40 authors = models.ManyToManyField(Person, related_name='books') 41 41 42 def __ repr__(self):42 def __str__(self): 43 43 return self.title 44 44 … … 56 56 fast_cars = FastCarManager() 57 57 58 def __ repr__(self):58 def __str__(self): 59 59 return self.name 60 60 … … 65 65 >>> p2.save() 66 66 >>> Person.objects.get_fun_people() 67 [ Bugs Bunny]67 [<Person: Bugs Bunny>] 68 68 69 69 # The RelatedManager used on the 'books' descriptor extends the default manager … … 90 90 91 91 >>> Book.published_objects.all() 92 [ How to program]92 [<Book: How to program>] 93 93 94 94 >>> c1 = Car(name='Corvette', mileage=21, top_speed=180) … … 97 97 >>> c2.save() 98 98 >>> Car.cars.order_by('name') 99 [ Corvette, Neon]99 [<Car: Corvette>, <Car: Neon>] 100 100 >>> Car.fast_cars.all() 101 [ Corvette]101 [<Car: Corvette>] 102 102 103 103 # Each model class gets a "_default_manager" attribute, which is a reference 104 104 # to the first manager defined in the class. In this case, it's "cars". 105 105 >>> Car._default_manager.order_by('name') 106 [ Corvette, Neon]106 [<Car: Corvette>, <Car: Neon>] 107 107 """ django/trunk/tests/modeltests/custom_methods/models.py
r3030 r3075 12 12 pub_date = models.DateField() 13 13 14 def __ repr__(self):14 def __str__(self): 15 15 return self.headline 16 16 … … 18 18 return self.pub_date == datetime.date.today() 19 19 20 def get_articles_from_same_day_1(self):20 def articles_from_same_day_1(self): 21 21 return Article.objects.filter(pub_date=self.pub_date).exclude(id=self.id) 22 22 23 def get_articles_from_same_day_2(self):23 def articles_from_same_day_2(self): 24 24 """ 25 25 Verbose version of get_articles_from_same_day_1, which does a custom … … 48 48 >>> a.was_published_today() 49 49 False 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>] 58 58 """ django/trunk/tests/modeltests/custom_pk/models.py
r2858 r3075 15 15 ordering = ('last_name', 'first_name') 16 16 17 def __ repr__(self):17 def __str__(self): 18 18 return "%s %s" % (self.first_name, self.last_name) 19 19 … … 24 24 verbose_name_plural = 'businesses' 25 25 26 def __ repr__(self):26 def __str__(self): 27 27 return self.name 28 28 … … 31 31 >>> dan.save() 32 32 >>> Employee.objects.all() 33 [ Dan Jones]33 [<Employee: Dan Jones>] 34 34 35 35 >>> fran = Employee(employee_code='XYZ456', first_name='Fran', last_name='Bones') 36 36 >>> fran.save() 37 37 >>> Employee.objects.all() 38 [ Fran Bones, Dan Jones]38 [<Employee: Fran Bones>, <Employee: Dan Jones>] 39 39 40 40 >>> Employee.objects.get(pk='ABC123') 41 Dan Jones 41 <Employee: Dan Jones> 42 42 >>> Employee.objects.get(pk='XYZ456') 43 Fran Bones 43 <Employee: Fran Bones> 44 44 >>> Employee.objects.get(pk='foo') 45 45 Traceback (most recent call last): … … 49 49 # Use the name of the primary key, rather than pk. 50 50 >>> Employee.objects.get(employee_code__exact='ABC123') 51 Dan Jones 51 <Employee: Dan Jones> 52 52 53 53 # Fran got married and changed her last name. … … 56 56 >>> fran.save() 57 57 >>> Employee.objects.filter(last_name__exact='Jones') 58 [ Dan Jones, Fran Jones]58 [<Employee: Dan Jones>, <Employee: Fran Jones>] 59 59 >>> Employee.objects.in_bulk(['ABC123', 'XYZ456']) 60 {'XYZ456': Fran Jones, 'ABC123': Dan Jones}60 {'XYZ456': <Employee: Fran Jones>, 'ABC123': <Employee: Dan Jones>} 61 61 62 62 >>> b = Business(name='Sears') … … 64 64 >>> b.employees.add(dan, fran) 65 65 >>> b.employees.all() 66 [ Dan Jones, Fran Jones]66 [<Employee: Dan Jones>, <Employee: Fran Jones>] 67 67 >>> fran.business_set.all() 68 [ Sears]68 [<Business: Sears>] 69 69 >>> Business.objects.in_bulk(['Sears']) 70 {'Sears': Sears}70 {'Sears': <Business: Sears>} 71 71 72 72 >>> Business.objects.filter(name__exact='Sears') 73 [ Sears]73 [<Business: Sears>] 74 74 >>> Business.objects.filter(pk='Sears') 75 [ Sears]75 [<Business: Sears>] 76 76 77 77 # Queries across tables, involving primary key 78 78 >>> Employee.objects.filter(business__name__exact='Sears') 79 [ Dan Jones, Fran Jones]79 [<Employee: Dan Jones>, <Employee: Fran Jones>] 80 80 >>> Employee.objects.filter(business__pk='Sears') 81 [ Dan Jones, Fran Jones]81 [<Employee: Dan Jones>, <Employee: Fran Jones>] 82 82 83 83 >>> Business.objects.filter(employees__employee_code__exact='ABC123') 84 [ Sears]84 [<Business: Sears>] 85 85 >>> Business.objects.filter(employees__pk='ABC123') 86 [ Sears]86 [<Business: Sears>] 87 87 >>> Business.objects.filter(employees__first_name__startswith='Fran') 88 [ Sears]88 [<Business: Sears>] 89 89 90 90 """ django/trunk/tests/modeltests/get_latest/models.py
r2858 r3075 18 18 get_latest_by = 'pub_date' 19 19 20 def __ repr__(self):20 def __str__(self): 21 21 return self.headline 22 22 … … 27 27 # Note that this model doesn't have "get_latest_by" set. 28 28 29 def __ repr__(self):29 def __str__(self): 30 30 return self.name 31 31 … … 50 50 # Get the latest Article. 51 51 >>> Article.objects.latest() 52 Article 4 52 <Article: Article 4> 53 53 54 54 # Get the latest Article that matches certain filters. 55 55 >>> Article.objects.filter(pub_date__lt=datetime(2005, 7, 27)).latest() 56 Article 1 56 <Article: Article 1> 57 57 58 58 # Pass a custom field name to latest() to change the field that's used to 59 59 # determine the latest object. 60 60 >>> Article.objects.latest('expire_date') 61 Article 1 61 <Article: Article 1> 62 62 63 63 >>> Article.objects.filter(pub_date__gt=datetime(2005, 7, 26)).latest('expire_date') 64 Article 3 64 <Article: Article 3> 65 65 66 66 # You can still use latest() with a model that doesn't have "get_latest_by" … … 76 76 77 77 >>> Person.objects.latest('birthday') 78 Stephanie 78 <Person: Stephanie> 79 79 """ django/trunk/tests/modeltests/lookup/models.py
r2858 r3075 13 13 ordering = ('-pub_date', 'headline') 14 14 15 def __ repr__(self):15 def __str__(self): 16 16 return self.headline 17 17 … … 62 62 # to objects. 63 63 >>> Article.objects.in_bulk([1, 2]) 64 {1: Article 1, 2: Article 2}64 {1: <Article: Article 1>, 2: <Article: Article 2>} 65 65 >>> Article.objects.in_bulk([3]) 66 {3: Article 3}66 {3: <Article: Article 3>} 67 67 >>> Article.objects.in_bulk([1000]) 68 68 {} … … 126 126 # fallback check. This guarantees that no records are skipped or duplicated. 127 127 >>> a1.get_next_by_pub_date() 128 Article 2 128 <Article: Article 2> 129 129 >>> a2.get_next_by_pub_date() 130 Article 3 130 <Article: Article 3> 131 131 >>> a3.get_next_by_pub_date() 132 Article 7 132 <Article: Article 7> 133 133 >>> a4.get_next_by_pub_date() 134 Article 6 134 <Article: Article 6> 135 135 >>> a5.get_next_by_pub_date() 136 136 Traceback (most recent call last): … … 138 138 DoesNotExist: Article matching query does not exist. 139 139 >>> a6.get_next_by_pub_date() 140 Article 5 140 <Article: Article 5> 141 141 >>> a7.get_next_by_pub_date() 142 Article 4 142 <Article: Article 4> 143 143 144 144 >>> a7.get_previous_by_pub_date() 145 Article 3 145 <Article: Article 3> 146 146 >>> a6.get_previous_by_pub_date() 147 Article 4 147 <Article: Article 4> 148 148 >>> a5.get_previous_by_pub_date() 149 Article 6 149 <Article: Article 6> 150 150 >>> a4.get_previous_by_pub_date() 151 Article 7 151 <Article: Article 7> 152 152 >>> a3.get_previous_by_pub_date() 153 Article 2 153 <Article: Article 2> 154 154 >>> a2.get_previous_by_pub_date() 155 Article 1 155 <Article: Article 1> 156 156 157 157 # Underscores and percent signs have special meaning in the underlying … … 160 160 >>> a8.save() 161 161 >>> 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>] 163 163 >>> Article.objects.filter(headline__startswith='Article_') 164 [ Article_ with underscore]164 [<Article: Article_ with underscore>] 165 165 >>> a9 = Article(headline='Article% with percent sign', pub_date=datetime(2005, 11, 21)) 166 166 >>> a9.save() 167 167 >>> 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>] 169 169 >>> Article.objects.filter(headline__startswith='Article%') 170 [ Article% with percent sign]170 [<Article: Article% with percent sign>] 171 171 172 172 # exclude() is the opposite of filter() when doing lookups: 173 173 >>> 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>] 175 175 >>> 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>] 177 177 >>> 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>] 179 179 """ django/trunk/tests/modeltests/m2m_intermediary/models.py
r2809 r3075 17 17 last_name = models.CharField(maxlength=30) 18 18 19 def __ repr__(self):19 def __str__(self): 20 20 return "%s %s" % (self.first_name, self.last_name) 21 21 … … 24 24 pub_date = models.DateField() 25 25 26 def __ repr__(self):26 def __str__(self): 27 27 return self.headline 28 28 … … 32 32 position = models.CharField(maxlength=100) 33 33 34 def __ repr__(self):35 return '% r(%s)' % (self.reporter, self.position)34 def __str__(self): 35 return '%s (%s)' % (self.reporter, self.position) 36 36 37 37 API_TESTS = """ … … 55 55 # Play around with the API. 56 56 >>> 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)>] 58 58 >>> w1.reporter 59 John Smith 59 <Reporter: John Smith> 60 60 >>> w2.reporter 61 Jane Doe 61 <Reporter: Jane Doe> 62 62 >>> w1.article 63 This is a test 63 <Article: This is a test> 64 64 >>> w2.article 65 This is a test 65 <Article: This is a test> 66 66 >>> r1.writer_set.all() 67 [ John Smith (Main writer)]67 [<Writer: John Smith (Main writer)>] 68 68 """ django/trunk/tests/modeltests/m2m_multiple/models.py
r2809 r3075 15 15 ordering = ('name',) 16 16 17 def __ repr__(self):17 def __str__(self): 18 18 return self.name 19 19 … … 26 26 ordering = ('pub_date',) 27 27 28 def __ repr__(self):28 def __str__(self): 29 29 return self.headline 30 30 … … 52 52 53 53 >>> a1.primary_categories.all() 54 [ Crime, News]54 [<Category: Crime>, <Category: News>] 55 55 56 56 >>> a2.primary_categories.all() 57 [ News, Sports]57 [<Category: News>, <Category: Sports>] 58 58 59 59 >>> a1.secondary_categories.all() 60 [ Life]60 [<Category: Life>] 61 61 62 62 63 63 >>> c1.primary_article_set.all() 64 [ Area man runs]64 [<Article: Area man runs>] 65 65 >>> c1.secondary_article_set.all() 66 66 [] 67 67 >>> c2.primary_article_set.all() 68 [ Area man steals, Area man runs]68 [<Article: Area man steals>, <Article: Area man runs>] 69 69 >>> c2.secondary_article_set.all() 70 70 [] 71 71 >>> c3.primary_article_set.all() 72 [ Area man steals]72 [<Article: Area man steals>] 73 73 >>> c3.secondary_article_set.all() 74 74 [] … … 76 76 [] 77 77 >>> c4.secondary_article_set.all() 78 [ Area man steals, Area man runs]78 [<Article: Area man steals>, <Article: Area man runs>] 79 79 """ django/trunk/tests/modeltests/m2m_recursive/models.py
r3031 r3075 20 20 idols = models.ManyToManyField('self', symmetrical=False, related_name='stalkers') 21 21 22 def __ repr__(self):22 def __str__(self): 23 23 return self.name 24 24 … … 42 42 # Who is friends with Anne? 43 43 >>> a.friends.all() 44 [ Bill, Chuck, David]44 [<Person: Bill>, <Person: Chuck>, <Person: David>] 45 45 46 46 # Who is friends with Bill? 47 47 >>> b.friends.all() 48 [ Anne]48 [<Person: Anne>] 49 49 50 50 # Who is friends with Chuck? 51 51 >>> c.friends.all() 52 [ Anne, David]52 [<Person: Anne>, <Person: David>] 53 53 54 54 # Who is friends with David? 55 55 >>> d.friends.all() 56 [ Anne, Chuck]56 [<Person: Anne>, <Person: Chuck>] 57 57 58 58 # Bill is already friends with Anne - add Anne again, but in the reverse direction … … 61 61 # Who is friends with Anne? 62 62 >>> a.friends.all() 63 [ Bill, Chuck, David]63 [<Person: Bill>, <Person: Chuck>, <Person: David>] 64 64 65 65 # Who is friends with Bill? 66 66 >>> b.friends.all() 67 [ Anne]67 [<Person: Anne>] 68 68 69 69 # Remove Anne from Bill's friends … … 72 72 # Who is friends with Anne? 73 73 >>> a.friends.all() 74 [ Chuck, David]74 [<Person: Chuck>, <Person: David>] 75 75 76 76 # Who is friends with Bill? … … 88 88 # Who is friends with Chuck? 89 89 >>> c.friends.all() 90 [ David]90 [<Person: David>] 91 91 92 92 # Who is friends with David? 93 93 >>> d.friends.all() 94 [ Chuck]94 [<Person: Chuck>] 95 95 96 96 … … 107 107 # Who are Anne's idols? 108 108 >>> a.idols.all() 109 [ Bill, Chuck, David]109 [<Person: Bill>, <Person: Chuck>, <Person: David>] 110 110 111 111 # Who is stalking Anne? 112 112 >>> a.stalkers.all() 113 [ Bill]113 [<Person: Bill>] 114 114 115 115 # Who are Bill's idols? 116 116 >>> b.idols.all() 117 [ Anne]117 [<Person: Anne>] 118 118 119 119 # Who is stalking Bill? 120 120 >>> b.stalkers.all() 121 [ Anne]121 [<Person: Anne>] 122 122 123 123 # Who are Chuck's idols? 124 124 >>> c.idols.all() 125 [ David]125 [<Person: David>] 126 126 127 127 # Who is stalking Chuck? 128 128 >>> c.stalkers.all() 129 [ Anne]129 [<Person: Anne>] 130 130 131 131 # Who are David's idols? … … 135 135 # Who is stalking David 136 136 >>> d.stalkers.all() 137 [ Anne, Chuck]137 [<Person: Anne>, <Person: Chuck>] 138 138 139 139 # Bill is already being stalked by Anne - add Anne again, but in the reverse direction … … 142 142 # Who are Anne's idols? 143 143 >>> a.idols.all() 144 [ Bill, Chuck, David]144 [<Person: Bill>, <Person: Chuck>, <Person: David>] 145 145 146 146 # Who is stalking Anne? 147 [ Bill]147 [<Person: Bill>] 148 148 149 149 # Who are Bill's idols 150 150 >>> b.idols.all() 151 [ Anne]151 [<Person: Anne>] 152 152 153 153 # Who is stalking Bill? 154 154 >>> b.stalkers.all() 155 [ Anne]155 [<Person: Anne>] 156 156 157 157 # Remove Anne from Bill's list of stalkers … … 160 160 # Who are Anne's idols? 161 161 >>> a.idols.all() 162 [ Chuck, David]162 [<Person: Chuck>, <Person: David>] 163 163 164 164 # Who is stalking Anne? 165 165 >>> a.stalkers.all() 166 [ Bill]166 [<Person: Bill>] 167 167 168 168 # Who are Bill's idols? 169 169 >>> b.idols.all() 170 [ Anne]170 [<Person: Anne>] 171 171 172 172 # Who is stalking Bill? … … 188 188 # Who is friends with David? 189 189 >>> d.stalkers.all() 190 [ Chuck]190 [<Person: Chuck>] 191 191 192 192 """ django/trunk/tests/modeltests/m2o_recursive2/models.py
r2809 r3075 15 15 father = models.ForeignKey('self', null=True, related_name='fathers_child_set') 16 16 17 def __ repr__(self):17 def __str__(self): 18 18 return self.full_name 19 19 … … 30 30 31 31 >>> kid.mother 32 Jane Smith 32 <Person: Jane Smith> 33 33 >>> kid.father 34 John Smith Senior 34 <Person: John Smith Senior> 35 35 >>> dad.fathers_child_set.all() 36 [ John Smith Junior]36 [<Person: John Smith Junior>] 37 37 >>> mom.mothers_child_set.all() 38 [ John Smith Junior]38 [<Person: John Smith Junior>] 39 39 >>> kid.mothers_child_set.all() 40 40 [] django/trunk/tests/modeltests/m2o_recursive/models.py
r2809 r3075 17 17 parent = models.ForeignKey('self', null=True, related_name='child_set') 18 18 19 def __ repr__(self):19 def __str__(self): 20 20 return self.name 21 21 … … 28 28 29 29 >>> r.child_set.all() 30 [ Child category]30 [<Category: Child category>] 31 31 >>> r.child_set.get(name__startswith='Child') 32 Child category 32 <Category: Child category> 33 33 >>> print r.parent 34 34 None … … 37 37 [] 38 38 >>> c.parent 39 Root category 39 <Category: Root category> 40 40 """ django/trunk/tests/modeltests/manipulators/models.py
r3031 r3075 11 11 last_name = models.CharField(maxlength=30) 12 12 13 def __ repr__(self):13 def __str__(self): 14 14 return "%s %s" % (self.first_name, self.last_name) 15 15 … … 19 19 release_date = models.DateField(blank=True, null=True) 20 20 21 def __ repr__(self):21 def __str__(self): 22 22 return self.name 23 23 … … 36 36 # Verify it worked. 37 37 >>> Musician.objects.all() 38 [ Ella Fitzgerald]38 [<Musician: Ella Fitzgerald>] 39 39 >>> [m1] == list(Musician.objects.all()) 40 40 True … … 70 70 # Verify it worked. 71 71 >>> Album.objects.all() 72 [ Ella and Basie]72 [<Album: Ella and Basie>] 73 73 >>> Album.objects.get().musician 74 Ella Fitzgerald 74 <Musician: Ella Fitzgerald> 75 75 76 76 # Create an Album with a release_date. … … 83 83 # Verify it worked. 84 84 >>> Album.objects.order_by('name') 85 [ Ella and Basie, Ultimate Ella]85 [<Album: Ella and Basie>, <Album: Ultimate Ella>] 86 86 >>> a2 = Album.objects.get(pk=2) 87 87 >>> a2 88 Ultimate Ella 88 <Album: Ultimate Ella> 89 89 >>> a2.release_date 90 90 datetime.date(2005, 2, 13) django/trunk/tests/modeltests/many_to_many/models.py
r2902 r3075 13 13 title = models.CharField(maxlength=30) 14 14 15 def __ repr__(self):15 def __str__(self): 16 16 return self.title 17 17 … … 23 23 publications = models.ManyToManyField(Publication) 24 24 25 def __ repr__(self):25 def __str__(self): 26 26 return self.headline 27 27 … … 59 59 # Article objects have access to their related Publication objects. 60 60 >>> a1.publications.all() 61 [ The Python Journal]61 [<Publication: The Python Journal>] 62 62 >>> 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>] 64 64 65 65 # Publication objects have access to their related Article objects. 66 66 >>> p2.article_set.all() 67 [ NASA uses Python]67 [<Article: NASA uses Python>] 68 68 >>> 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>] 70 70 >>> Publication.objects.get(id=4).article_set.all() 71 [ NASA uses Python]71 [<Article: NASA uses Python>] 72 72 73 73 # We can perform kwarg queries across m2m relationships 74 74 >>> Article.objects.filter(publications__id__exact=1) 75 [ Django lets you build Web apps easily, NASA uses Python]
