Ticket #20535: #20535-tests.diff

File #20535-tests.diff, 1.4 KB (added by Kronuz, 2 years ago)
  • django/tests/modeltests/m2m_through/models.py

    class Person(models.Model): 
    1616        return self.name
    1717
    1818@python_2_unicode_compatible
     19class 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
    1924class Group(models.Model):
    2025    name = models.CharField(max_length=128)
    2126    members = models.ManyToManyField(Person, through='Membership')
  • django/tests/modeltests/m2m_through/tests.py

    from operator import attrgetter 
    55
    66from django.test import TestCase
    77
    8 from .models import (Person, Group, Membership, CustomMembership,
     8from .models import (Relationship, Person, Group, Membership, CustomMembership,
    99    PersonSelfRefM2M, Friendship)
    1010
    1111
    class M2mThroughTests(TestCase): 
    343343            ],
    344344            attrgetter("name")
    345345        )
     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)
Back to Top