Ticket #7125: failing_many_to_one_mutiple_test_2.diff

File failing_many_to_one_mutiple_test_2.diff, 1.6 KB (added by oyvind, 16 years ago)

Better patch for modeltest

  • tests/modeltests/many_to_one/models.py

    diff --git a/tests/modeltests/many_to_one/models.py b/tests/modeltests/many_to_one/models.py
    index dfb17b8..434fa2e 100644
    a b class Article(models.Model):  
    2525    class Meta:
    2626        ordering = ('headline',)
    2727
     28class Category(models.Model):
     29    name = models.CharField(max_length=20)
     30
     31class Record(models.Model):
     32    category = models.ForeignKey(Category)
     33
     34class Relation(models.Model):
     35    left = models.ForeignKey(Record, related_name='left_set')
     36    right = models.ForeignKey(Record, related_name='right_set')
     37
    2838__test__ = {'API_TESTS':"""
    2939# Create a few Reporters.
    3040>>> r = Reporter(first_name='John', last_name='Smith', email='john@example.com')
    True  
    292302[datetime.datetime(1980, 4, 1, 0, 0)]
    293303>>> Article.objects.select_related().dates('pub_date', 'year')
    294304[datetime.datetime(1980, 1, 1, 0, 0)]
     305
     306# Test of multiple ForeignKeys to the same model
     307# Add some categories/records/relations
     308
     309>>> c1 = Category.objects.create(name='First')
     310>>> c2 = Category.objects.create(name='Second')
     311>>> r1 = Record.objects.create(category=c1)
     312>>> r2 = Record.objects.create(category=c1)
     313>>> r3 = Record.objects.create(category=c2)
     314>>> r4 = Record.objects.create(category=c2)
     315>>> r = Relation.objects.create(left=r1, right=r2)
     316>>> r = Relation.objects.create(left=r3, right=r4)
     317>>> r = Relation.objects.create(left=r1, right=r3)
     318
     319# Yields wrong sql
     320>>> Relation.objects.filter(left__category__name__in=['Second'], right__category__name__in=['First']).query.as_sql()
     321
    295322"""}
Back to Top