mirror of
https://github.com/django/django.git
synced 2025-11-25 05:04:26 +00:00
Fixed #28344 -- Allowed customizing queryset in Model.refresh_from_db()/arefresh_from_db().
The from_queryset parameter can be used to: - use a custom Manager - lock the row until the end of transaction - select additional related objects
This commit is contained in:
parent
f3d10546a8
commit
f92641a636
5 changed files with 111 additions and 14 deletions
|
|
@ -23,3 +23,14 @@ class AsyncModelOperationTest(TestCase):
|
|||
await SimpleModel.objects.filter(pk=self.s1.pk).aupdate(field=20)
|
||||
await self.s1.arefresh_from_db()
|
||||
self.assertEqual(self.s1.field, 20)
|
||||
|
||||
async def test_arefresh_from_db_from_queryset(self):
|
||||
await SimpleModel.objects.filter(pk=self.s1.pk).aupdate(field=20)
|
||||
with self.assertRaises(SimpleModel.DoesNotExist):
|
||||
await self.s1.arefresh_from_db(
|
||||
from_queryset=SimpleModel.objects.filter(field=0)
|
||||
)
|
||||
await self.s1.arefresh_from_db(
|
||||
from_queryset=SimpleModel.objects.filter(field__gt=0)
|
||||
)
|
||||
self.assertEqual(self.s1.field, 20)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue