Changeset 2244
- Timestamp:
- 02/03/06 14:03:04 (3 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/magic-removal/tests/modeltests/m2m_multiple/models.py
r2195 r2244 6 6 7 7 Set ``related_name`` to designate what the reverse relationship is called. 8 9 Set ``singular`` to designate what the category object is called. This is10 required if a model has multiple ``ManyToManyFields`` to the same object.11 8 """ 12 9 … … 24 21 headline = models.CharField(maxlength=50) 25 22 pub_date = models.DateTimeField() 26 primary_categories = models.ManyToManyField(Category, 27 singular='primary_category', related_name='primary_article') 28 secondary_categories = models.ManyToManyField(Category, 29 singular='secondary_category', related_name='secondary_article') 23 primary_categories = models.ManyToManyField(Category, related_name='primary_article_set') 24 secondary_categories = models.ManyToManyField(Category, related_name='secondary_article_set') 30 25 class Meta: 31 26 ordering = ('pub_date',) … … 64 59 # would cause a conflict because the "primary_categories" and 65 60 # "secondary_categories" fields both relate to Category. 66 >>> a1.primary_categor y_set.all()61 >>> a1.primary_categories.all() 67 62 [Crime, News] 68 63 69 64 # Ditto for the "primary_category" here. 70 >>> a2.primary_categor y_set.all()65 >>> a2.primary_categories.all() 71 66 [News, Sports] 72 67 73 68 # Ditto for the "secondary_category" here. 74 >>> a1.secondary_categor y_set.all()69 >>> a1.secondary_categories.all() 75 70 [Life] 76 71 django/branches/magic-removal/tests/modeltests/many_to_many/models.py
r2195 r2244 57 57 58 58 # Article objects have access to their related Publication objects. 59 >>> a1.publication _set.all()59 >>> a1.publications.all() 60 60 [The Python Journal] 61 >>> a2.publication _set.all()61 >>> a2.publications.all() 62 62 [The Python Journal, Science News, Science Weekly] 63 63 … … 100 100 [Science News, Science Weekly] 101 101 >>> a1 = Article.objects.get(pk=1) 102 >>> a1.publication _set.all()102 >>> a1.publications.all() 103 103 [] 104 104
