Ticket #11850: 11850-test.patch
File 11850-test.patch, 2.0 KB (added by , 13 years ago) |
---|
-
modeltests/m2m_intermediary/tests.py
4 4 5 5 from django.test import TestCase 6 6 7 from .models import Reporter, Article, Writer 7 from .models import Reporter, Article, Writer, First, Second, Through 8 8 9 9 10 10 class M2MIntermediaryTests(TestCase): … … 38 38 ], 39 39 lambda w: (unicode(w.reporter), w.position) 40 40 ) 41 42 def test_intermediary_ordering(self): 43 f = First.objects.create(title='First') 44 # Create out of order, in case pk ordering is 'default' in the DBMS 45 s2 = Second.objects.create(title='Second 2') 46 s3 = Second.objects.create(title='Second 3') 47 s1 = Second.objects.create(title='Second 1') 48 49 t2 = Through.objects.create(first=f, second=s2, order=2) 50 t1 = Through.objects.create(first=f, second=s1, order=1) 51 t3 = Through.objects.create(first=f, second=s2, order=3) 52 53 self.assertQuerysetEqual( 54 f.seconds.all(), [ 55 u'Second 1', 56 u'Second 2', 57 u'Second 3', 58 ], 59 lambda w: w.title 60 ) -
modeltests/m2m_intermediary/models.py
35 35 def __unicode__(self): 36 36 return u'%s (%s)' % (self.reporter, self.position) 37 37 38 class First(models.Model): 39 title = models.CharField(max_length=10) 40 seconds = models.ManyToManyField('Second', through='Through') 41 42 class Second(models.Model): 43 title = models.CharField(max_length=10) 44 45 class Through(models.Model): 46 first = models.ForeignKey('First') 47 second = models.ForeignKey('Second') 48 order = models.IntegerField() 49 50 class Meta: 51 ordering = ('order',) 52