1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #28820 -- Eliminated an extra query with QuerySet.update() on proxy models.

This commit is contained in:
Yan Mitrofanov 2017-11-20 18:25:01 +03:00 committed by Tim Graham
parent a5f1e5809f
commit 54e5c4a00e
2 changed files with 8 additions and 1 deletions

View File

@ -122,7 +122,7 @@ class UpdateQuery(Query):
'Cannot update model field %r (only non-relations and '
'foreign keys permitted).' % field
)
if model is not self.get_meta().model:
if model is not self.get_meta().concrete_model:
self.add_related_update(model, field, val)
continue
values_seq.append((field, model, val))

View File

@ -276,6 +276,13 @@ class ProxyModelTests(TestCase):
resp = [u.name for u in UserProxy.objects.all()]
self.assertEqual(resp, ['Bruce'])
def test_proxy_update(self):
user = User.objects.create(name='Bruce')
with self.assertNumQueries(1):
UserProxy.objects.filter(id=user.id).update(name='George')
user.refresh_from_db()
self.assertEqual(user.name, 'George')
def test_select_related(self):
"""
We can still use `select_related()` to include related models in our