summaryrefslogtreecommitdiff
path: root/tests/update
diff options
context:
space:
mode:
authorKaren Tracey <kmtracey@gmail.com>2014-11-15 14:36:41 -0500
committerTim Graham <timograham@gmail.com>2014-11-16 15:44:13 +0100
commitdec93d89912965f94f9e942f0a89ca586fb91454 (patch)
treeb10f26d744c95ffc9fafd295e03f2d9fe0b78668 /tests/update
parentde912495ab1c3b3e05e79068861ab6b3b5f5c32e (diff)
downloaddjango-dec93d89912965f94f9e942f0a89ca586fb91454.tar.gz
Fixed #21612 -- Made QuerySet.update() respect to_field
Diffstat (limited to 'tests/update')
-rw-r--r--tests/update/models.py8
-rw-r--r--tests/update/tests.py15
2 files changed, 22 insertions, 1 deletions
diff --git a/tests/update/models.py b/tests/update/models.py
index ebc9c3353c..e0b391d0cd 100644
--- a/tests/update/models.py
+++ b/tests/update/models.py
@@ -42,3 +42,11 @@ class C(models.Model):
class D(C):
a = models.ForeignKey(A)
+
+
+class Foo(models.Model):
+ target = models.CharField(max_length=10, unique=True)
+
+
+class Bar(models.Model):
+ foo = models.ForeignKey(Foo, to_field='target')
diff --git a/tests/update/tests.py b/tests/update/tests.py
index 95e9069972..578b3ab440 100644
--- a/tests/update/tests.py
+++ b/tests/update/tests.py
@@ -2,7 +2,7 @@ from __future__ import unicode_literals
from django.test import TestCase
-from .models import A, B, D, DataPoint, RelatedPoint
+from .models import A, B, D, DataPoint, RelatedPoint, Foo, Bar
class SimpleTest(TestCase):
@@ -125,3 +125,16 @@ class AdvancedTests(TestCase):
method = DataPoint.objects.all()[:2].update
self.assertRaises(AssertionError, method,
another_value='another thing')
+
+ def test_update_respects_to_field(self):
+ """
+ Update of an FK field which specifies a to_field works.
+ """
+ a_foo = Foo.objects.create(target='aaa')
+ b_foo = Foo.objects.create(target='bbb')
+ bar = Bar.objects.create(foo=a_foo)
+ self.assertEqual(bar.foo_id, a_foo.target)
+ bar_qs = Bar.objects.filter(pk=bar.pk)
+ self.assertEqual(bar_qs[0].foo_id, a_foo.target)
+ bar_qs.update(foo=b_foo)
+ self.assertEqual(bar_qs[0].foo_id, b_foo.target)