diff options
| author | Justin Bronn <jbronn@gmail.com> | 2008-04-28 14:08:46 +0000 |
|---|---|---|
| committer | Justin Bronn <jbronn@gmail.com> | 2008-04-28 14:08:46 +0000 |
| commit | e5b52f90f0ca2b3b3490c22d869f8c2afc14a526 (patch) | |
| tree | 37712fea84257f0c35b400571205face5a4c4ca8 /tests | |
| parent | a125a1c9b646368702bb14f26c1a6b09cff3e5a0 (diff) | |
gis: Merged revisions 7485-7491,7493-7497 via svnmerge from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7498 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeltests/many_to_one/models.py | 17 | ||||
| -rw-r--r-- | tests/regressiontests/queries/models.py | 47 |
2 files changed, 62 insertions, 2 deletions
diff --git a/tests/modeltests/many_to_one/models.py b/tests/modeltests/many_to_one/models.py index 6616f8b55e..53ad4466bb 100644 --- a/tests/modeltests/many_to_one/models.py +++ b/tests/modeltests/many_to_one/models.py @@ -246,7 +246,7 @@ FieldError: Cannot resolve keyword 'reporter_id' into field. Choices are: headli >>> Reporter.objects.filter(article__reporter__exact=r).distinct() [<Reporter: John Smith>] -# Check that implied __exact also works +# Check that implied __exact also works. >>> Reporter.objects.filter(article__reporter=r).distinct() [<Reporter: John Smith>] @@ -266,11 +266,24 @@ True >>> Reporter.objects.order_by('first_name') [<Reporter: John Smith>] -# Deletes using a join in the query +# You can delete using a JOIN in the query. >>> Reporter.objects.filter(article__headline__startswith='This').delete() >>> Reporter.objects.all() [] >>> Article.objects.all() [] +# Check that Article.objects.select_related().dates() works properly when +# there are multiple Articles with the same date but different foreign-key +# objects (Reporters). +>>> r1 = Reporter.objects.create(first_name='Mike', last_name='Royko', email='royko@suntimes.com') +>>> r2 = Reporter.objects.create(first_name='John', last_name='Kass', email='jkass@tribune.com') +>>> a1 = Article.objects.create(headline='First', pub_date=datetime(1980, 4, 23), reporter=r1) +>>> a2 = Article.objects.create(headline='Second', pub_date=datetime(1980, 4, 23), reporter=r2) +>>> Article.objects.select_related().dates('pub_date', 'day') +[datetime.datetime(1980, 4, 23, 0, 0)] +>>> Article.objects.select_related().dates('pub_date', 'month') +[datetime.datetime(1980, 4, 1, 0, 0)] +>>> Article.objects.select_related().dates('pub_date', 'year') +[datetime.datetime(1980, 1, 1, 0, 0)] """} diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py index 483aa7218c..6fd361ec19 100644 --- a/tests/regressiontests/queries/models.py +++ b/tests/regressiontests/queries/models.py @@ -117,6 +117,24 @@ class LoopZ(models.Model): class Meta: ordering = ['z'] +# A model and custom default manager combination. +class CustomManager(models.Manager): + def get_query_set(self): + return super(CustomManager, self).get_query_set().filter(public=True, + tag__name='t1') + +class ManagedModel(models.Model): + data = models.CharField(max_length=10) + tag = models.ForeignKey(Tag) + public = models.BooleanField(default=True) + + objects = CustomManager() + normal_manager = models.Manager() + + def __unicode__(self): + return self.data + + __test__ = {'API_TESTS':""" >>> t1 = Tag(name='t1') >>> t1.save() @@ -654,5 +672,34 @@ Bug #7045 -- extra tables used to crash SQL construction on the second use. >>> s = qs.query.as_sql() >>> s = qs.query.as_sql() # test passes if this doesn't raise an exception. +Bug #7098 -- Make sure semi-deprecated ordering by related models syntax still +works. +>>> Item.objects.values('note__note').order_by('queries_note.note', 'id') +[{'note__note': u'n2'}, {'note__note': u'n3'}, {'note__note': u'n3'}, {'note__note': u'n3'}] + +Bug #7096 -- Make sure exclude() with multiple conditions continues to work. +>>> Tag.objects.filter(parent=t1, name='t3').order_by('name') +[<Tag: t3>] +>>> Tag.objects.exclude(parent=t1, name='t3').order_by('name') +[<Tag: t1>, <Tag: t2>, <Tag: t4>, <Tag: t5>] +>>> Item.objects.exclude(tags__name='t1', name='one').order_by('name').distinct() +[<Item: four>, <Item: three>, <Item: two>] +>>> Item.objects.filter(name__in=['three', 'four']).exclude(tags__name='t1').order_by('name') +[<Item: four>, <Item: three>] + +More twisted cases, involving nested negations. +>>> Item.objects.exclude(~Q(tags__name='t1', name='one')) +[<Item: one>] +>>> Item.objects.filter(~Q(tags__name='t1', name='one'), name='two') +[<Item: two>] +>>> Item.objects.exclude(~Q(tags__name='t1', name='one'), name='two') +[<Item: four>, <Item: one>, <Item: three>] + +Bug #7095 +Updates that are filtered on the model being updated are somewhat tricky to get +in MySQL. This exercises that case. +>>> mm = ManagedModel.objects.create(data='mm1', tag=t1, public=True) +>>> ManagedModel.objects.update(data='mm') + """} |
