Fixed #21612 -- Made QuerySet.update() respect to_field

This commit is contained in:
Karen Tracey 2014-11-15 14:36:41 -05:00 committed by Tim Graham
parent de912495ab
commit dec93d8991
3 changed files with 24 additions and 3 deletions

View file

@ -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)