magic-removal: Fixed many_to_many and m2m_multiple model unit tests to use correct many-to-many manager name (the field name, not object_name +'_set')

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2244 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-02-03 20:03:04 +00:00
parent b9c2b3e83f
commit 6fa54ec9fd
2 changed files with 8 additions and 13 deletions

View File

@ -5,9 +5,6 @@ In this example, an Article can have many Categories (as "primary") and many
Categories (as "secondary"). Categories (as "secondary").
Set ``related_name`` to designate what the reverse relationship is called. Set ``related_name`` to designate what the reverse relationship is called.
Set ``singular`` to designate what the category object is called. This is
required if a model has multiple ``ManyToManyFields`` to the same object.
""" """
from django.db import models from django.db import models
@ -23,10 +20,8 @@ class Category(models.Model):
class Article(models.Model): class Article(models.Model):
headline = models.CharField(maxlength=50) headline = models.CharField(maxlength=50)
pub_date = models.DateTimeField() pub_date = models.DateTimeField()
primary_categories = models.ManyToManyField(Category, primary_categories = models.ManyToManyField(Category, related_name='primary_article_set')
singular='primary_category', related_name='primary_article') secondary_categories = models.ManyToManyField(Category, related_name='secondary_article_set')
secondary_categories = models.ManyToManyField(Category,
singular='secondary_category', related_name='secondary_article')
class Meta: class Meta:
ordering = ('pub_date',) ordering = ('pub_date',)
@ -63,15 +58,15 @@ True
# specified the "singular" parameter, Django would just use "category", which # specified the "singular" parameter, Django would just use "category", which
# would cause a conflict because the "primary_categories" and # would cause a conflict because the "primary_categories" and
# "secondary_categories" fields both relate to Category. # "secondary_categories" fields both relate to Category.
>>> a1.primary_category_set.all() >>> a1.primary_categories.all()
[Crime, News] [Crime, News]
# Ditto for the "primary_category" here. # Ditto for the "primary_category" here.
>>> a2.primary_category_set.all() >>> a2.primary_categories.all()
[News, Sports] [News, Sports]
# Ditto for the "secondary_category" here. # Ditto for the "secondary_category" here.
>>> a1.secondary_category_set.all() >>> a1.secondary_categories.all()
[Life] [Life]

View File

@ -56,9 +56,9 @@ True
True True
# Article objects have access to their related Publication objects. # Article objects have access to their related Publication objects.
>>> a1.publication_set.all() >>> a1.publications.all()
[The Python Journal] [The Python Journal]
>>> a2.publication_set.all() >>> a2.publications.all()
[The Python Journal, Science News, Science Weekly] [The Python Journal, Science News, Science Weekly]
# Publication objects have access to their related Article objects. # Publication objects have access to their related Article objects.
@ -99,7 +99,7 @@ True
>>> Publication.objects.all() >>> Publication.objects.all()
[Science News, Science Weekly] [Science News, Science Weekly]
>>> a1 = Article.objects.get(pk=1) >>> a1 = Article.objects.get(pk=1)
>>> a1.publication_set.all() >>> a1.publications.all()
[] []
# If we delete an Article, its Publications won't be able to access it. # If we delete an Article, its Publications won't be able to access it.