Ticket #17315: django-exclude-bug.diff

File django-exclude-bug.diff, 2.2 KB (added by absoludity@…, 13 years ago)

Diff adding failing test

  • tests/modeltests/lookup/tests.py

     
    436436                '<Article: Article 1>',
    437437            ])
    438438
     439    def test_exclude_multi_valued_relationship(self):
     440        # Only Author 3 has published an "Article_ with underscore"
     441        # before 2006.
     442        a8 = Article.objects.create(   
     443            headline='Article_ with underscore',
     444            pub_date=datetime(2011, 11, 20),
     445            author=self.au1)
     446        a9 = Article.objects.create(
     447            headline='Article_ with underscore',
     448            pub_date=datetime(2011, 11, 20),
     449            author=self.au2)
     450        au3 = Author.objects.create(name='Author 3')
     451        a10 = Article.objects.create(
     452            headline='Article_ with underscore',
     453            pub_date=datetime(2005, 11, 21),
     454            author=au3)
     455
     456        self.assertQuerysetEqual(
     457            Author.objects.filter(
     458                article__headline='Article_ with underscore',
     459                article__pub_date__lt=datetime(2006, 1, 1)),
     460            [
     461                '<Author: Author 3>',
     462            ])
     463
     464        self.assertQuerysetEqual(
     465            Author.objects.exclude(
     466                article__headline='Article_ with underscore',
     467                article__pub_date__lt=datetime(2006, 1, 1)),
     468            [
     469                '<Author: Author 1>',
     470                '<Author: Author 2>',
     471            ])
     472
    439473    def test_none(self):
    440474       # none() returns an EmptyQuerySet that behaves like any other QuerySet object
    441475        self.assertQuerysetEqual(Article.objects.none(), [])
  • tests/modeltests/lookup/models.py

     
    1212    class Meta:
    1313        ordering = ('name', )
    1414
     15    def __unicode__(self):
     16        return self.name
     17
    1518class Article(models.Model):
    1619    headline = models.CharField(max_length=100)
    1720    pub_date = models.DateTimeField() 
Back to Top