django-ninja-aio-crud 0.7.7__tar.gz → 0.8.0__tar.gz
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.7 → django_ninja_aio_crud-0.8.0}/PKG-INFO +6 -1
- {django_ninja_aio_crud-0.7.7 → django_ninja_aio_crud-0.8.0}/README.md +5 -0
- {django_ninja_aio_crud-0.7.7 → django_ninja_aio_crud-0.8.0}/ninja_aio/__init__.py +1 -1
- {django_ninja_aio_crud-0.7.7 → django_ninja_aio_crud-0.8.0}/ninja_aio/models.py +52 -3
- {django_ninja_aio_crud-0.7.7 → django_ninja_aio_crud-0.8.0}/ninja_aio/views.py +7 -3
- {django_ninja_aio_crud-0.7.7 → django_ninja_aio_crud-0.8.0}/LICENSE +0 -0
- {django_ninja_aio_crud-0.7.7 → django_ninja_aio_crud-0.8.0}/ninja_aio/api.py +0 -0
- {django_ninja_aio_crud-0.7.7 → django_ninja_aio_crud-0.8.0}/ninja_aio/auth.py +0 -0
- {django_ninja_aio_crud-0.7.7 → django_ninja_aio_crud-0.8.0}/ninja_aio/exceptions.py +0 -0
- {django_ninja_aio_crud-0.7.7 → django_ninja_aio_crud-0.8.0}/ninja_aio/parsers.py +0 -0
- {django_ninja_aio_crud-0.7.7 → django_ninja_aio_crud-0.8.0}/ninja_aio/renders.py +0 -0
- {django_ninja_aio_crud-0.7.7 → django_ninja_aio_crud-0.8.0}/ninja_aio/schemas.py +0 -0
- {django_ninja_aio_crud-0.7.7 → django_ninja_aio_crud-0.8.0}/ninja_aio/types.py +0 -0
- {django_ninja_aio_crud-0.7.7 → django_ninja_aio_crud-0.8.0}/pyproject.toml +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
|
|
@@ -181,7 +181,12 @@ class Foo(ModelSerializer):
|
|
|
181
181
|
excludes = ["id", "name"]
|
|
182
182
|
optionals = [("bar", str), ("active", bool)]
|
|
183
183
|
```
|
|
184
|
+
- ModelSerializer comes out also with methods executed on object save, them are:
|
|
184
185
|
|
|
186
|
+
1. on_create_before_save: code executed on object creation but before saving;
|
|
187
|
+
1. on_create_after_save: code executed on object creation but after saving;
|
|
188
|
+
1. before_save: code executed on every save but before saving;
|
|
189
|
+
1. after_save: code executed on every save but after saving;
|
|
185
190
|
|
|
186
191
|
|
|
187
192
|
### APIViewSet
|
|
@@ -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
|
|
@@ -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
|
|
|
@@ -75,6 +75,7 @@ class APIViewSet:
|
|
|
75
75
|
pagination_class: type[AsyncPaginationBase] = PageNumberPagination
|
|
76
76
|
query_params: dict[str, tuple[type, ...]] = {}
|
|
77
77
|
disable: list[type[VIEW_TYPES]] = []
|
|
78
|
+
api_route_path: str = ""
|
|
78
79
|
|
|
79
80
|
def __init__(self) -> None:
|
|
80
81
|
self.error_codes = ERROR_CODES
|
|
@@ -86,6 +87,9 @@ class APIViewSet:
|
|
|
86
87
|
self.router = Router(tags=[self.router_tag])
|
|
87
88
|
self.path = "/"
|
|
88
89
|
self.path_retrieve = f"{{{self.model_util.model_pk_name}}}/"
|
|
90
|
+
self.api_route_path = (
|
|
91
|
+
self.api_route_path or self.model_util.verbose_name_path_resolver()
|
|
92
|
+
)
|
|
89
93
|
|
|
90
94
|
@property
|
|
91
95
|
def _crud_views(self):
|
|
@@ -239,7 +243,7 @@ class APIViewSet:
|
|
|
239
243
|
|
|
240
244
|
AUTHENTICATED VIEW:
|
|
241
245
|
|
|
242
|
-
@self.router.get(some_path, response=some_schema, auth=self.
|
|
246
|
+
@self.router.get(some_path, response=some_schema, auth=self.auth)
|
|
243
247
|
async def some_method(request, *args, **kwargs):
|
|
244
248
|
pass
|
|
245
249
|
|
|
@@ -266,6 +270,6 @@ class APIViewSet:
|
|
|
266
270
|
|
|
267
271
|
def add_views_to_route(self):
|
|
268
272
|
return self.api.add_router(
|
|
269
|
-
f"{self.
|
|
273
|
+
f"{self.api_route_path}/",
|
|
270
274
|
self.add_views(),
|
|
271
275
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|