diff options
Diffstat (limited to 'parts/django/tests/modeltests/m2m_intermediary')
3 files changed, 0 insertions, 74 deletions
diff --git a/parts/django/tests/modeltests/m2m_intermediary/__init__.py b/parts/django/tests/modeltests/m2m_intermediary/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/parts/django/tests/modeltests/m2m_intermediary/__init__.py +++ /dev/null diff --git a/parts/django/tests/modeltests/m2m_intermediary/models.py b/parts/django/tests/modeltests/m2m_intermediary/models.py deleted file mode 100644 index 8042a52..0000000 --- a/parts/django/tests/modeltests/m2m_intermediary/models.py +++ /dev/null @@ -1,36 +0,0 @@ -""" -9. Many-to-many relationships via an intermediary table - -For many-to-many relationships that need extra fields on the intermediary -table, use an intermediary model. - -In this example, an ``Article`` can have multiple ``Reporter`` objects, and -each ``Article``-``Reporter`` combination (a ``Writer``) has a ``position`` -field, which specifies the ``Reporter``'s position for the given article -(e.g. "Staff writer"). -""" - -from django.db import models - -class Reporter(models.Model): - first_name = models.CharField(max_length=30) - last_name = models.CharField(max_length=30) - - def __unicode__(self): - return u"%s %s" % (self.first_name, self.last_name) - -class Article(models.Model): - headline = models.CharField(max_length=100) - pub_date = models.DateField() - - def __unicode__(self): - return self.headline - -class Writer(models.Model): - reporter = models.ForeignKey(Reporter) - article = models.ForeignKey(Article) - position = models.CharField(max_length=100) - - def __unicode__(self): - return u'%s (%s)' % (self.reporter, self.position) - diff --git a/parts/django/tests/modeltests/m2m_intermediary/tests.py b/parts/django/tests/modeltests/m2m_intermediary/tests.py deleted file mode 100644 index 5f35741..0000000 --- a/parts/django/tests/modeltests/m2m_intermediary/tests.py +++ /dev/null @@ -1,38 +0,0 @@ -from datetime import datetime - -from django.test import TestCase - -from models import Reporter, Article, Writer - - -class M2MIntermediaryTests(TestCase): - def test_intermeiary(self): - r1 = Reporter.objects.create(first_name="John", last_name="Smith") - r2 = Reporter.objects.create(first_name="Jane", last_name="Doe") - - a = Article.objects.create( - headline="This is a test", pub_date=datetime(2005, 7, 27) - ) - - w1 = Writer.objects.create(reporter=r1, article=a, position="Main writer") - w2 = Writer.objects.create(reporter=r2, article=a, position="Contributor") - - self.assertQuerysetEqual( - a.writer_set.select_related().order_by("-position"), [ - ("John Smith", "Main writer"), - ("Jane Doe", "Contributor"), - ], - lambda w: (unicode(w.reporter), w.position) - ) - self.assertEqual(w1.reporter, r1) - self.assertEqual(w2.reporter, r2) - - self.assertEqual(w1.article, a) - self.assertEqual(w2.article, a) - - self.assertQuerysetEqual( - r1.writer_set.all(), [ - ("John Smith", "Main writer") - ], - lambda w: (unicode(w.reporter), w.position) - ) |