Ticket #20535: #20535-tests.diff
File #20535-tests.diff, 1.4 KB (added by , 11 years ago) |
---|
-
django/tests/modeltests/m2m_through/models.py
class Person(models.Model): 16 16 return self.name 17 17 18 18 @python_2_unicode_compatible 19 class Relationship(models.Model): 20 from_person = models.ForeignKey(Person, related_name='idols') 21 to_person = models.ForeignKey(Person, related_name='followers') 22 23 @python_2_unicode_compatible 19 24 class Group(models.Model): 20 25 name = models.CharField(max_length=128) 21 26 members = models.ManyToManyField(Person, through='Membership') -
django/tests/modeltests/m2m_through/tests.py
from operator import attrgetter 5 5 6 6 from django.test import TestCase 7 7 8 from .models import ( Person, Group, Membership, CustomMembership,8 from .models import (Relationship, Person, Group, Membership, CustomMembership, 9 9 PersonSelfRefM2M, Friendship) 10 10 11 11 … … class M2mThroughTests(TestCase): 343 343 ], 344 344 attrgetter("name") 345 345 ) 346 347 def test_ticket_20535_m2m_trim(self): 348 qs = Relationship.objects.filter(from_person__followers__from_person=self.bob) 349 self.assertEqual(str(qs.query).count('JOIN'), 1) 350 351 def test_ticket_20535_m2m_no_trim(self): 352 qs = Relationship.objects.filter(from_person__followers__from_person=self.bob, from_person__name='Jane') 353 self.assertEqual(str(qs.query).count('JOIN'), 2)