Skip to content

Commit 77e57cd

Browse files
committed
added async ways to clean and validate the forms
1 parent 1955667 commit 77e57cd

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

django_async_extensions/aforms/models.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ class AsyncModelForm(ModelForm):
1010
async def from_async(cls, *args, **kwargs):
1111
return await sync_to_async(cls)(*args, **kwargs)
1212

13+
@property
14+
async def aerrors(self):
15+
if self._errors is None:
16+
await self.afull_clean()
17+
return self._errors
18+
19+
async def ais_valid(self):
20+
return self.is_bound and not await self.aerrors
21+
22+
async def afull_clean(self):
23+
return await sync_to_async(self.full_clean)()
24+
1325
async def _asave_m2m(self):
1426
"""
1527
Save the many-to-many fields and generic relations for this form.

0 commit comments

Comments
 (0)