diff options
| author | Jon Janzen <jon@jonjanzen.com> | 2022-11-03 19:57:33 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-11-09 10:32:40 +0100 |
| commit | 321ecb40f4da842926e1bc07e11df4aabe53ca4b (patch) | |
| tree | 3a306ec0bc38c90eb95d8adceaecc3017e1b3d06 /django/contrib/contenttypes | |
| parent | 41e8931c2cc68d8b2de4219be930e2c305b4eba1 (diff) | |
Fixed #34135 -- Added async-compatible interface to related managers.
Diffstat (limited to 'django/contrib/contenttypes')
| -rw-r--r-- | django/contrib/contenttypes/fields.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/django/contrib/contenttypes/fields.py b/django/contrib/contenttypes/fields.py index ce2a096cc2..72b9e7631a 100644 --- a/django/contrib/contenttypes/fields.py +++ b/django/contrib/contenttypes/fields.py @@ -689,6 +689,11 @@ def create_generic_related_manager(superclass, rel): add.alters_data = True + async def aadd(self, *objs, bulk=True): + return await sync_to_async(self.add)(*objs, bulk=bulk) + + aadd.alters_data = True + def remove(self, *objs, bulk=True): if not objs: return @@ -696,11 +701,21 @@ def create_generic_related_manager(superclass, rel): remove.alters_data = True + async def aremove(self, *objs, bulk=True): + return await sync_to_async(self.remove)(*objs, bulk=bulk) + + aremove.alters_data = True + def clear(self, *, bulk=True): self._clear(self, bulk) clear.alters_data = True + async def aclear(self, *, bulk=True): + return await sync_to_async(self.clear)(bulk=bulk) + + aclear.alters_data = True + def _clear(self, queryset, bulk): self._remove_prefetched_objects() db = router.db_for_write(self.model, instance=self.instance) @@ -740,6 +755,11 @@ def create_generic_related_manager(superclass, rel): set.alters_data = True + async def aset(self, objs, *, bulk=True, clear=False): + return await sync_to_async(self.set)(objs, bulk=bulk, clear=clear) + + aset.alters_data = True + def create(self, **kwargs): self._remove_prefetched_objects() kwargs[self.content_type_field_name] = self.content_type |
