diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index 7ea9ef9..59220db 100644
|
a
|
b
|
class SQLUpdateCompiler(SQLCompiler):
|
| 1012 | 1012 | raise FieldError("Aggregate functions are not allowed in this query") |
| 1013 | 1013 | elif hasattr(val, 'prepare_database_save'): |
| 1014 | 1014 | if field.remote_field: |
| 1015 | | val = val.prepare_database_save(field) |
| | 1015 | val = field.get_db_prep_save(val.prepare_database_save(field), |
| | 1016 | connection=self.connection) |
| 1016 | 1017 | else: |
| 1017 | 1018 | raise TypeError("Database is trying to update a relational field " |
| 1018 | 1019 | "of type %s with a value of type %s. Make sure " |
diff --git a/tests/update/models.py b/tests/update/models.py
index e0b391d..08706ef 100644
|
a
|
b
|
|
| 2 | 2 | Tests for the update() queryset method that allows in-place, multi-object |
| 3 | 3 | updates. |
| 4 | 4 | """ |
| | 5 | import uuid |
| 5 | 6 | |
| 6 | 7 | from django.db import models |
| 7 | 8 | from django.utils import six |
| … |
… |
class Foo(models.Model):
|
| 50 | 51 | |
| 51 | 52 | class Bar(models.Model): |
| 52 | 53 | foo = models.ForeignKey(Foo, to_field='target') |
| | 54 | |
| | 55 | |
| | 56 | class UUIDPK(models.Model): |
| | 57 | id = models.UUIDField(primary_key=True, default=uuid.uuid4) |
| | 58 | |
| | 59 | |
| | 60 | class UUIDRelation(models.Model): |
| | 61 | relation = models.ForeignKey(UUIDPK) |
diff --git a/tests/update/tests.py b/tests/update/tests.py
index 1ed316c..a0b5934 100644
|
a
|
b
|
from __future__ import unicode_literals
|
| 2 | 2 | |
| 3 | 3 | from django.test import TestCase |
| 4 | 4 | |
| 5 | | from .models import A, B, D, Bar, DataPoint, Foo, RelatedPoint |
| | 5 | from .models import A, B, D, Bar, DataPoint, Foo, RelatedPoint, UUIDPK, UUIDRelation |
| 6 | 6 | |
| 7 | 7 | |
| 8 | 8 | class SimpleTest(TestCase): |
| … |
… |
class AdvancedTests(TestCase):
|
| 138 | 138 | self.assertEqual(bar_qs[0].foo_id, a_foo.target) |
| 139 | 139 | bar_qs.update(foo=b_foo) |
| 140 | 140 | self.assertEqual(bar_qs[0].foo_id, b_foo.target) |
| | 141 | |
| | 142 | |
| | 143 | class UUIDRelationTests(TestCase): |
| | 144 | |
| | 145 | def setUp(self): |
| | 146 | self.u1 = UUIDPK.objects.create() |
| | 147 | u2 = UUIDPK.objects.create() |
| | 148 | UUIDRelation.objects.create(relation=u2) |
| | 149 | |
| | 150 | def test_update_uuid_fk_with_model_instance(self): |
| | 151 | """ |
| | 152 | Update of a FK to a model with UUID pk using a model instance |
| | 153 | """ |
| | 154 | UUIDRelation.objects.update(relation=self.u1) |
| | 155 | |
| | 156 | def test_update_uuid_fk_with_uuid_instance(self): |
| | 157 | """ |
| | 158 | Update of a FK to a model with UUID pk using a UUID instance |
| | 159 | """ |
| | 160 | UUIDRelation.objects.update(relation=self.u1.pk) |