Skip to content

Commit 9bbbb50

Browse files
committed
fix User model's manager + bumping version
1 parent a769432 commit 9bbbb50

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ This is an on going projects, not all model methods are ported.
114114
| `Model.objects.async_ordered` || |
115115
| `__aiter__` || |
116116
| `__repr__` || |
117+
| `Model.objects.async_iterator || |
117118

118119

119120
### Model:
@@ -126,11 +127,12 @@ This is an on going projects, not all model methods are ported.
126127
| `...` || |
127128

128129

129-
### User Model
130+
### User Model / Manager
130131
| methods | supported | comments |
131132
|----------------------------|------------|----------|
132-
| `UserModel.is_authenticated` || |
133-
| `UserModel.is_super_user` || |
133+
| `UserModel.is_authenticated` || |
134+
| `UserModel.is_super_user` || |
135+
| `UserModel.objects.async_create_user` || |
134136
| `...` || |
135137

136138

django_async_orm/apps.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from django.apps import AppConfig, apps
33

4-
from django_async_orm.manager import AsyncManager
4+
from django_async_orm.utils import patch_manager
55

66

77
class AsyncOrmConfig(AppConfig):
@@ -10,5 +10,4 @@ class AsyncOrmConfig(AppConfig):
1010
def ready(self):
1111
logging.info('AsyncORM: patching models')
1212
for model in apps.get_models(include_auto_created=True):
13-
model.objects = AsyncManager()
14-
model.objects.model = model
13+
patch_manager(model)

django_async_orm/utils.py

+22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import asyncio
22

3+
from django_async_orm.manager import AsyncManager
4+
5+
36
class AsyncIter:
47
def __init__(self, iterable):
58
self._iter = iter(iterable)
@@ -14,3 +17,22 @@ async def __anext__(self):
1417
raise StopAsyncIteration
1518
await asyncio.sleep(0)
1619
return element
20+
21+
22+
def async_user_manager_factory():
23+
from django.contrib.auth.models import UserManager
24+
25+
class AsyncUserManager(UserManager, AsyncManager):
26+
pass
27+
28+
return AsyncUserManager
29+
30+
31+
def patch_manager(model):
32+
from django.contrib.auth.models import UserManager
33+
async_manager_cls = AsyncManager
34+
if isinstance(model.objects, UserManager):
35+
async_manager_cls = async_user_manager_factory()
36+
37+
model.objects = async_manager_cls()
38+
model.objects.model = model

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-async-orm"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
description = "Bringing async capabilities to django ORM"
55
authors = ["SkanderBM <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)