django-ninja-aio-crud 0.7.8__py3-none-any.whl → 0.8.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {django_ninja_aio_crud-0.7.8.dist-info → django_ninja_aio_crud-0.8.0.dist-info}/METADATA +6 -1
- {django_ninja_aio_crud-0.7.8.dist-info → django_ninja_aio_crud-0.8.0.dist-info}/RECORD +7 -7
- {django_ninja_aio_crud-0.7.8.dist-info → django_ninja_aio_crud-0.8.0.dist-info}/WHEEL +1 -1
- ninja_aio/__init__.py +1 -1
- ninja_aio/models.py +52 -3
- ninja_aio/views.py +2 -2
- {django_ninja_aio_crud-0.7.8.dist-info → django_ninja_aio_crud-0.8.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: django-ninja-aio-crud
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
4
4
|
Summary: Django Ninja AIO CRUD - Rest Framework
|
|
5
5
|
Author: Giuseppe Casillo
|
|
6
6
|
Requires-Python: >=3.10
|
|
@@ -213,7 +213,12 @@ class Foo(ModelSerializer):
|
|
|
213
213
|
excludes = ["id", "name"]
|
|
214
214
|
optionals = [("bar", str), ("active", bool)]
|
|
215
215
|
```
|
|
216
|
+
- ModelSerializer comes out also with methods executed on object save, them are:
|
|
216
217
|
|
|
218
|
+
1. on_create_before_save: code executed on object creation but before saving;
|
|
219
|
+
1. on_create_after_save: code executed on object creation but after saving;
|
|
220
|
+
1. before_save: code executed on every save but before saving;
|
|
221
|
+
1. after_save: code executed on every save but after saving;
|
|
217
222
|
|
|
218
223
|
|
|
219
224
|
### APIViewSet
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
ninja_aio/__init__.py,sha256=
|
|
1
|
+
ninja_aio/__init__.py,sha256=4Y_TTHJMyRwXROgTk4ceYBEInHJp915fVqn25INc0mw,119
|
|
2
2
|
ninja_aio/api.py,sha256=Fe6l3YCy7MW5TY4-Lbl80CFuK2NT2Y7tHfmqPk6Mqak,1735
|
|
3
3
|
ninja_aio/auth.py,sha256=fKboioU4sezPukKJukIwiboxml_KV7irhCH3vGYt5pU,1008
|
|
4
4
|
ninja_aio/exceptions.py,sha256=gPnZX1Do2GXudbU8wDYkwhO70Qj0ZNrIJJ2UXRs9vYk,2241
|
|
5
|
-
ninja_aio/models.py,sha256=
|
|
5
|
+
ninja_aio/models.py,sha256=eliA49Bvga9hLgjOIzTg4WTxZ8usBy74LyUcp5Njh7c,18566
|
|
6
6
|
ninja_aio/parsers.py,sha256=e_4lGCPV7zs-HTqtdJTc8yQD2KPAn9njbL8nF_Mmgkc,153
|
|
7
7
|
ninja_aio/renders.py,sha256=mHeKNJtmDhZmgFpS9B6SPn5uZFcyVXrsoMhr149LeW8,1555
|
|
8
8
|
ninja_aio/schemas.py,sha256=EgRkfhnzZqwGvdBmqlZixMtMcoD1ZxV_qzJ3fmaAy20,113
|
|
9
9
|
ninja_aio/types.py,sha256=TJSGlA7bt4g9fvPhJ7gzH5tKbLagPmZUzfgttEOp4xs,468
|
|
10
|
-
ninja_aio/views.py,sha256=
|
|
11
|
-
django_ninja_aio_crud-0.
|
|
12
|
-
django_ninja_aio_crud-0.
|
|
13
|
-
django_ninja_aio_crud-0.
|
|
14
|
-
django_ninja_aio_crud-0.
|
|
10
|
+
ninja_aio/views.py,sha256=sMxIymLQ6dpeuf4-akYI1PrNzpfJf0S0iS2cC8BnHXM,9387
|
|
11
|
+
django_ninja_aio_crud-0.8.0.dist-info/licenses/LICENSE,sha256=yrDAYcm0gRp_Qyzo3GQa4BjYjWRkAhGC8QRva__RYq0,1073
|
|
12
|
+
django_ninja_aio_crud-0.8.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
|
|
13
|
+
django_ninja_aio_crud-0.8.0.dist-info/METADATA,sha256=3Bc2ezvyizII3UNfHexWaH-1pp39uRNO87foJDdkCDc,14126
|
|
14
|
+
django_ninja_aio_crud-0.8.0.dist-info/RECORD,,
|
ninja_aio/__init__.py
CHANGED
ninja_aio/models.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import asyncio
|
|
1
2
|
import base64
|
|
2
3
|
from typing import Any
|
|
3
4
|
|
|
@@ -142,7 +143,7 @@ class ModelUtil:
|
|
|
142
143
|
):
|
|
143
144
|
rel_util = ModelUtil(field_obj.related_model)
|
|
144
145
|
rel: ModelSerializer = await rel_util.get_object(
|
|
145
|
-
request,
|
|
146
|
+
request, v.get(rel_util.model_pk_name)
|
|
146
147
|
)
|
|
147
148
|
if isinstance(field_obj, models.ForeignKey):
|
|
148
149
|
for rel_k, rel_v in v.items():
|
|
@@ -162,8 +163,7 @@ class ModelUtil:
|
|
|
162
163
|
pk = (await self.model.objects.acreate(**payload)).pk
|
|
163
164
|
obj = await self.get_object(request, pk)
|
|
164
165
|
if isinstance(self.model, ModelSerializerMeta):
|
|
165
|
-
await obj.custom_actions(customs)
|
|
166
|
-
await obj.post_create()
|
|
166
|
+
await asyncio.gather(obj.custom_actions(customs), obj.post_create())
|
|
167
167
|
return await self.read_s(request, obj, obj_schema)
|
|
168
168
|
|
|
169
169
|
async def read_s(
|
|
@@ -491,3 +491,52 @@ class ModelSerializer(models.Model, metaclass=ModelSerializerMeta):
|
|
|
491
491
|
@classmethod
|
|
492
492
|
def generate_related_s(cls) -> Schema:
|
|
493
493
|
return cls._generate_model_schema("Related")
|
|
494
|
+
|
|
495
|
+
def after_save(self):
|
|
496
|
+
"""
|
|
497
|
+
Override this method to execute code after the object
|
|
498
|
+
has been saved
|
|
499
|
+
"""
|
|
500
|
+
pass
|
|
501
|
+
|
|
502
|
+
def before_save(self):
|
|
503
|
+
"""
|
|
504
|
+
Override this method to execute code before the object
|
|
505
|
+
has been saved
|
|
506
|
+
"""
|
|
507
|
+
pass
|
|
508
|
+
|
|
509
|
+
def on_create_after_save(self):
|
|
510
|
+
"""
|
|
511
|
+
Override this method to execute code after the object
|
|
512
|
+
has been created
|
|
513
|
+
"""
|
|
514
|
+
pass
|
|
515
|
+
|
|
516
|
+
def on_create_before_save(self):
|
|
517
|
+
"""
|
|
518
|
+
Override this method to execute code before the object
|
|
519
|
+
has been created
|
|
520
|
+
"""
|
|
521
|
+
pass
|
|
522
|
+
|
|
523
|
+
def on_delete(self):
|
|
524
|
+
"""
|
|
525
|
+
Override this method to execute code after the object
|
|
526
|
+
has been deleted
|
|
527
|
+
"""
|
|
528
|
+
pass
|
|
529
|
+
|
|
530
|
+
def save(self, *args, **kwargs):
|
|
531
|
+
if self._state.adding:
|
|
532
|
+
self.on_create_before_save()
|
|
533
|
+
self.before_save()
|
|
534
|
+
super().save(*args, **kwargs)
|
|
535
|
+
if self._state.adding:
|
|
536
|
+
self.on_create_after_save()
|
|
537
|
+
self.after_save()
|
|
538
|
+
|
|
539
|
+
def delete(self, *args, **kwargs):
|
|
540
|
+
res = super().delete(*args, **kwargs)
|
|
541
|
+
self.on_delete()
|
|
542
|
+
return res
|
ninja_aio/views.py
CHANGED
|
@@ -46,7 +46,7 @@ class APIView:
|
|
|
46
46
|
|
|
47
47
|
AUTHENTICATED VIEW:
|
|
48
48
|
|
|
49
|
-
@self.router.get(some_path, response=some_schema, auth=self.
|
|
49
|
+
@self.router.get(some_path, response=some_schema, auth=self.auth)
|
|
50
50
|
async def some_method(request, *args, **kwargs):
|
|
51
51
|
pass
|
|
52
52
|
|
|
@@ -243,7 +243,7 @@ class APIViewSet:
|
|
|
243
243
|
|
|
244
244
|
AUTHENTICATED VIEW:
|
|
245
245
|
|
|
246
|
-
@self.router.get(some_path, response=some_schema, auth=self.
|
|
246
|
+
@self.router.get(some_path, response=some_schema, auth=self.auth)
|
|
247
247
|
async def some_method(request, *args, **kwargs):
|
|
248
248
|
pass
|
|
249
249
|
|
{django_ninja_aio_crud-0.7.8.dist-info → django_ninja_aio_crud-0.8.0.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|