Kaydet (Commit) 54e5c4a0 authored tarafından Yan Mitrofanov's avatar Yan Mitrofanov Kaydeden (comit) Tim Graham

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

üst a5f1e580
...@@ -122,7 +122,7 @@ class UpdateQuery(Query): ...@@ -122,7 +122,7 @@ class UpdateQuery(Query):
'Cannot update model field %r (only non-relations and ' 'Cannot update model field %r (only non-relations and '
'foreign keys permitted).' % field '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) self.add_related_update(model, field, val)
continue continue
values_seq.append((field, model, val)) values_seq.append((field, model, val))
......
...@@ -276,6 +276,13 @@ class ProxyModelTests(TestCase): ...@@ -276,6 +276,13 @@ class ProxyModelTests(TestCase):
resp = [u.name for u in UserProxy.objects.all()] resp = [u.name for u in UserProxy.objects.all()]
self.assertEqual(resp, ['Bruce']) 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): def test_select_related(self):
""" """
We can still use `select_related()` to include related models in our We can still use `select_related()` to include related models in our
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment