Fixed #28820 -- Eliminated an extra query with QuerySet.update() on proxy models.
This commit is contained in:
parent
a5f1e5809f
commit
54e5c4a00e
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue