1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +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:
Aivars Kalvans
2023-12-10 21:43:34 +02:00
committed by Mariusz Felisiak
parent f3d10546a8
commit f92641a636
5 changed files with 111 additions and 14 deletions

View File

@@ -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)