Ticket #11437: m2m-regress-tests.diff

File m2m-regress-tests.diff, 2.0 KB (added by Alex Gaynor, 15 years ago)

I'm unable to reproduce with these tests, can you let me know what else needs to be done to reproduce this issue?

  • new file tests/regressiontests/multiple_database_regress/models.py

    diff --git a/tests/regressiontests/multiple_database_regress/__init__.py b/tests/regressiontests/multiple_database_regress/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/multiple_database_regress/models.py b/tests/regressiontests/multiple_database_regress/models.py
    new file mode 100644
    index 0000000..5f370dc
    - +  
     1from django.db import models
     2
     3class Author(models.Model):
     4    name = models.CharField(max_length=100)
     5
     6    def __unicode__(self):
     7        return self.name
     8
     9class Book(models.Model):
     10    title = models.CharField(max_length=100)
     11    authors = models.ManyToManyField(Author, through='Authorship')
     12
     13    def __unicode__(self):
     14        return self.title
     15
     16class Authorship(models.Model):
     17    author = models.ForeignKey(Author, db_column='Author_ID')
     18    book = models.ForeignKey(Book, db_column='Book_ID')
  • new file tests/regressiontests/multiple_database_regress/tests.py

    diff --git a/tests/regressiontests/multiple_database_regress/tests.py b/tests/regressiontests/multiple_database_regress/tests.py
    new file mode 100644
    index 0000000..84c534d
    - +  
     1from django.test import TestCase
     2
     3from models import Author, Book, Authorship
     4
     5class ManyToManyWithCustomColumnTestCase(TestCase):
     6    def setUp(self):
     7        self.a = Author.objects.create(name="J.R.R. Tolkien")
     8        self.b1 = Book.objects.create(title="The Hobbit")
     9        self.b2 = Book.objects.create(title="The Fellowship of the Ring")
     10        self.auth1 = Authorship.objects.create(author=self.a, book=self.b1)
     11        self.auth2 = Authorship.objects.create(author=self.a, book=self.b2)
     12
     13    def test_query(self):
     14        self.assertEqual(list(self.a.book_set.all()), [self.b1, self.b2])
     15        self.assertEqual(list(self.b1.authors.all()), [self.a])
     16        self.assertEqual(list(self.a.authorship_set.all()), [self.auth1, self.auth2])
     17        self.assertEqual(list(self.b1.authorship_set.all()), [self.auth1])
Back to Top