Django

Code

Ticket #11437: m2m-regress-tests.diff

File m2m-regress-tests.diff, 2.0 kB (added by Alex, 8 months ago)

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

  • /dev/null

    old new  
     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') 
  • /dev/null

    old new  
     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])