summaryrefslogtreecommitdiff
path: root/tests/foreign_object/tests.py
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2013-06-28 17:32:57 +0100
committerAndrew Godwin <andrew@aeracode.org>2013-06-28 17:32:57 +0100
commit7a47ba6f6aeca36b8b092dbafd36abb342d34d4b (patch)
treee959922f7d4d08057225459e31697f410e26df26 /tests/foreign_object/tests.py
parente2d7e83256234251a81ad3388428f6579795a672 (diff)
parent48dd1e63bbb93479666208535a56f8c7c4aeab3a (diff)
Merge remote-tracking branch 'core/master' into schema-alteration
Conflicts: django/db/backends/__init__.py django/db/models/fields/related.py tests/field_deconstruction/tests.py
Diffstat (limited to 'tests/foreign_object/tests.py')
-rw-r--r--tests/foreign_object/tests.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/foreign_object/tests.py b/tests/foreign_object/tests.py
index 69636ee49b..670fc94dc5 100644
--- a/tests/foreign_object/tests.py
+++ b/tests/foreign_object/tests.py
@@ -1,9 +1,10 @@
import datetime
from operator import attrgetter
-from .models import Country, Person, Group, Membership, Friendship, Article, ArticleTranslation
+from .models import Country, Person, Group, Membership, Friendship, Article, ArticleTranslation, ArticleTag, ArticleIdea
from django.test import TestCase
from django.utils.translation import activate
+from django.core.exceptions import FieldError
from django import forms
class MultiColumnFKTests(TestCase):
@@ -321,6 +322,24 @@ class MultiColumnFKTests(TestCase):
with self.assertRaisesMessage(Article.DoesNotExist, 'ArticleTranslation has no article'):
referrer.article
+ def test_foreign_key_related_query_name(self):
+ a1 = Article.objects.create(pub_date=datetime.date.today())
+ ArticleTag.objects.create(article=a1, name="foo")
+ self.assertEqual(Article.objects.filter(tag__name="foo").count(), 1)
+ self.assertEqual(Article.objects.filter(tag__name="bar").count(), 0)
+ with self.assertRaises(FieldError):
+ Article.objects.filter(tags__name="foo")
+
+ def test_many_to_many_related_query_name(self):
+ a1 = Article.objects.create(pub_date=datetime.date.today())
+ i1 = ArticleIdea.objects.create(name="idea1")
+ a1.ideas.add(i1)
+ self.assertEqual(Article.objects.filter(idea_things__name="idea1").count(), 1)
+ self.assertEqual(Article.objects.filter(idea_things__name="idea2").count(), 0)
+ with self.assertRaises(FieldError):
+ Article.objects.filter(ideas__name="idea1")
+
+
class FormsTests(TestCase):
# ForeignObjects should not have any form fields, currently the user needs
# to manually deal with the foreignobject relation.