diff options
| author | Anssi Kääriäinen <akaariai@gmail.com> | 2013-02-28 15:04:12 +0200 |
|---|---|---|
| committer | Anssi Kääriäinen <akaariai@gmail.com> | 2013-02-28 15:05:48 +0200 |
| commit | 06de130dae8b7a6c95143077d7a82fab37da0bc0 (patch) | |
| tree | bacdf702b0a0f8c4a91d7c695f754453161b3657 /tests | |
| parent | 481f3f13b54a5cacc5b67b32c4ada267fc709d21 (diff) | |
Fixed #12823 -- Was already fixed in master, tests added
Also added a little improvement to sql/query.py to get rid of
non-necessary IS NOT NULL check.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/queries/models.py | 16 | ||||
| -rw-r--r-- | tests/queries/tests.py | 25 |
2 files changed, 40 insertions, 1 deletions
diff --git a/tests/queries/models.py b/tests/queries/models.py index 28c858557b..c8598371a6 100644 --- a/tests/queries/models.py +++ b/tests/queries/models.py @@ -454,3 +454,19 @@ class Program(models.Model): class Channel(models.Model): programs = models.ManyToManyField(Program) identifier = models.OneToOneField(Identifier) + +class Book(models.Model): + title = models.TextField() + chapter = models.ForeignKey('Chapter') + +class Chapter(models.Model): + title = models.TextField() + paragraph = models.ForeignKey('Paragraph') + + +class Paragraph(models.Model): + text = models.TextField() + page = models.ManyToManyField('Page') + +class Page(models.Model): + text = models.TextField() diff --git a/tests/queries/tests.py b/tests/queries/tests.py index 82a8de08be..2c17cb5e76 100644 --- a/tests/queries/tests.py +++ b/tests/queries/tests.py @@ -24,7 +24,8 @@ from .models import (Annotation, Article, Author, Celebrity, Child, Cover, Node, ObjectA, ObjectB, ObjectC, CategoryItem, SimpleCategory, SpecialCategory, OneToOneCategory, NullableName, ProxyCategory, SingleObject, RelatedObject, ModelA, ModelD, Responsibility, Job, - JobResponsibilities, BaseA, Identifier, Program, Channel) + JobResponsibilities, BaseA, Identifier, Program, Channel, Page, Paragraph, + Chapter, Book) class BaseQuerysetTest(TestCase): @@ -2638,3 +2639,25 @@ class ManyToManyExcludeTest(TestCase): Identifier.objects.exclude(program__channel=None).order_by('name'), ['<Identifier: program>'] ) + + def test_ticket_12823(self): + pg3 = Page.objects.create(text='pg3') + pg2 = Page.objects.create(text='pg2') + pg1 = Page.objects.create(text='pg1') + pa1 = Paragraph.objects.create(text='pa1') + pa1.page = [pg1, pg2] + pa2 = Paragraph.objects.create(text='pa2') + pa2.page = [pg2, pg3] + pa3 = Paragraph.objects.create(text='pa3') + ch1 = Chapter.objects.create(title='ch1', paragraph=pa1) + ch2 = Chapter.objects.create(title='ch2', paragraph=pa2) + ch3 = Chapter.objects.create(title='ch3', paragraph=pa3) + b1 = Book.objects.create(title='b1', chapter=ch1) + b2 = Book.objects.create(title='b2', chapter=ch2) + b3 = Book.objects.create(title='b3', chapter=ch3) + q = Book.objects.exclude(chapter__paragraph__page__text='pg1') + self.assertNotIn('IS NOT NULL', str(q.query)) + self.assertEqual(len(q), 2) + self.assertNotIn(b1, q) + self.assertIn(b2, q) + self.assertIn(b3, q) |
