summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-03-12 12:41:58 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-03-12 12:41:58 +0000
commit428450b7a90d92239b170160e5926f83085fa476 (patch)
tree85f47ae81a123d27c141f0ee4f31409292333793 /tests
parentf3ed30f377051c3fef3d184241ed5271fbe61854 (diff)
queryset-refactor: Refactored the way values() works so that it works properly
across inherited models. Completely by accident, this also allows values() queries to include fields from related models, providing it is crossing a single-valued relation (one-to-one, many-to-one). Many-to-many values() fields still aren't supported, since that requires actual thinking. So this refs #5768. git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7230 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/many_to_one/models.py5
-rw-r--r--tests/modeltests/model_inheritance/models.py13
2 files changed, 18 insertions, 0 deletions
diff --git a/tests/modeltests/many_to_one/models.py b/tests/modeltests/many_to_one/models.py
index c55b0e3e7c..d2c8e87fc1 100644
--- a/tests/modeltests/many_to_one/models.py
+++ b/tests/modeltests/many_to_one/models.py
@@ -250,6 +250,11 @@ FieldError: Cannot resolve keyword 'reporter_id' into field. Choices are: headli
>>> Reporter.objects.filter(article__reporter=r).distinct()
[<Reporter: John Smith>]
+# It's possible to use values() calls across many-to-one relations.
+>>> d = {'reporter__first_name': u'John', 'reporter__last_name': u'Smith'}
+>>> list(Article.objects.filter(reporter=r).distinct().values('reporter__first_name', 'reporter__last_name')) == [d]
+True
+
# If you delete a reporter, his articles will be deleted.
>>> Article.objects.all()
[<Article: John's second story>, <Article: Paul's story>, <Article: This is a test>, <Article: This is a test>, <Article: This is a test>]
diff --git a/tests/modeltests/model_inheritance/models.py b/tests/modeltests/model_inheritance/models.py
index d6ff586ee3..3f13dabc72 100644
--- a/tests/modeltests/model_inheritance/models.py
+++ b/tests/modeltests/model_inheritance/models.py
@@ -14,6 +14,10 @@ Both styles are demonstrated here.
from django.db import models
+#
+# Abstract base classes
+#
+
class CommonInfo(models.Model):
name = models.CharField(max_length=50)
age = models.PositiveIntegerField()
@@ -34,6 +38,10 @@ class Student(CommonInfo):
class Meta:
pass
+#
+# Multi-table inheritance
+#
+
class Place(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=80)
@@ -227,4 +235,9 @@ True
>>> r1.name
u'Demon Puppies'
+# The values() command also works on fields from parent models.
+>>> d = {'rating': 4, 'name': u'Ristorante Miron'}
+>>> list(ItalianRestaurant.objects.values('name', 'rating')) == [d]
+True
+
"""}