django-ninja-aio-crud 0.7.2__py3-none-any.whl → 0.7.4__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.2.dist-info → django_ninja_aio_crud-0.7.4.dist-info}/METADATA +3 -2
- django_ninja_aio_crud-0.7.4.dist-info/RECORD +14 -0
- {django_ninja_aio_crud-0.7.2.dist-info → django_ninja_aio_crud-0.7.4.dist-info}/WHEEL +1 -1
- django_ninja_aio_crud-0.7.4.dist-info/licenses/LICENSE +21 -0
- ninja_aio/__init__.py +1 -1
- ninja_aio/models.py +48 -68
- ninja_aio/types.py +2 -2
- django_ninja_aio_crud-0.7.2.dist-info/RECORD +0 -13
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: django-ninja-aio-crud
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.4
|
|
4
4
|
Summary: Django Ninja AIO CRUD - Rest Framework
|
|
5
5
|
Author: Giuseppe Casillo
|
|
6
6
|
Requires-Python: >=3.10
|
|
@@ -22,6 +22,7 @@ Classifier: Framework :: Django
|
|
|
22
22
|
Classifier: Framework :: AsyncIO
|
|
23
23
|
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
24
24
|
Classifier: Topic :: Internet :: WWW/HTTP
|
|
25
|
+
License-File: LICENSE
|
|
25
26
|
Requires-Dist: django-ninja >=1.3.0
|
|
26
27
|
Requires-Dist: joserfc >=1.0.0
|
|
27
28
|
Requires-Dist: orjson >= 3.10.7
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
ninja_aio/__init__.py,sha256=mOBOfTz2rTIcK2p5GfONfds9MeHL41sf2sHhoR1WYag,119
|
|
2
|
+
ninja_aio/api.py,sha256=Fe6l3YCy7MW5TY4-Lbl80CFuK2NT2Y7tHfmqPk6Mqak,1735
|
|
3
|
+
ninja_aio/auth.py,sha256=fKboioU4sezPukKJukIwiboxml_KV7irhCH3vGYt5pU,1008
|
|
4
|
+
ninja_aio/exceptions.py,sha256=gPnZX1Do2GXudbU8wDYkwhO70Qj0ZNrIJJ2UXRs9vYk,2241
|
|
5
|
+
ninja_aio/models.py,sha256=-Zh3UFmV3iIUIbMN93uN7v-VInoWp215Y_RXK3izuQI,17115
|
|
6
|
+
ninja_aio/parsers.py,sha256=e_4lGCPV7zs-HTqtdJTc8yQD2KPAn9njbL8nF_Mmgkc,153
|
|
7
|
+
ninja_aio/renders.py,sha256=mHeKNJtmDhZmgFpS9B6SPn5uZFcyVXrsoMhr149LeW8,1555
|
|
8
|
+
ninja_aio/schemas.py,sha256=EgRkfhnzZqwGvdBmqlZixMtMcoD1ZxV_qzJ3fmaAy20,113
|
|
9
|
+
ninja_aio/types.py,sha256=TJSGlA7bt4g9fvPhJ7gzH5tKbLagPmZUzfgttEOp4xs,468
|
|
10
|
+
ninja_aio/views.py,sha256=qROag0OsMeVUXcnUYKV7ZmWj4E0F-QH52PI2-56zVRs,9263
|
|
11
|
+
django_ninja_aio_crud-0.7.4.dist-info/licenses/LICENSE,sha256=yrDAYcm0gRp_Qyzo3GQa4BjYjWRkAhGC8QRva__RYq0,1073
|
|
12
|
+
django_ninja_aio_crud-0.7.4.dist-info/WHEEL,sha256=_2ozNFCLWc93bK4WKHCO-eDUENDlo-dgc9cU3qokYO4,82
|
|
13
|
+
django_ninja_aio_crud-0.7.4.dist-info/METADATA,sha256=ZjawRtUD5hMHi_u0klFeVtu8BXXzqgRph-5TELJ1_OQ,13759
|
|
14
|
+
django_ninja_aio_crud-0.7.4.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Giuseppe Casillo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
ninja_aio/__init__.py
CHANGED
ninja_aio/models.py
CHANGED
|
@@ -16,7 +16,7 @@ from django.db.models.fields.related_descriptors import (
|
|
|
16
16
|
)
|
|
17
17
|
|
|
18
18
|
from .exceptions import SerializeError
|
|
19
|
-
from .types import S_TYPES,
|
|
19
|
+
from .types import S_TYPES, F_TYPES, SCHEMA_TYPES, ModelSerializerMeta
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
class ModelUtil:
|
|
@@ -277,6 +277,17 @@ class ModelSerializer(models.Model, metaclass=ModelSerializerMeta):
|
|
|
277
277
|
custom_fields=reverse_rels + customs,
|
|
278
278
|
exclude=excludes,
|
|
279
279
|
)
|
|
280
|
+
case "Related":
|
|
281
|
+
fields, customs = cls.get_related_schema_data()
|
|
282
|
+
if not fields and not customs:
|
|
283
|
+
return None
|
|
284
|
+
return create_schema(
|
|
285
|
+
model=cls,
|
|
286
|
+
name=f"{cls._meta.model_name}SchemaRelated",
|
|
287
|
+
fields=fields,
|
|
288
|
+
custom_fields=customs,
|
|
289
|
+
)
|
|
290
|
+
|
|
280
291
|
fields = cls.get_fields(s_type)
|
|
281
292
|
optionals = cls.get_optional_fields(s_type)
|
|
282
293
|
customs = cls.get_custom_fields(s_type) + optionals
|
|
@@ -335,75 +346,31 @@ class ModelSerializer(models.Model, metaclass=ModelSerializerMeta):
|
|
|
335
346
|
pass
|
|
336
347
|
|
|
337
348
|
@classmethod
|
|
338
|
-
def
|
|
339
|
-
|
|
340
|
-
for
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
349
|
+
def get_related_schema_data(cls):
|
|
350
|
+
fields = cls.get_fields("read")
|
|
351
|
+
custom_f = {name: (value, default) for name, value, default in cls.get_custom_fields("read")}
|
|
352
|
+
_related_fields = []
|
|
353
|
+
for f in fields + list(custom_f.keys()):
|
|
354
|
+
field_obj = getattr(cls, f)
|
|
355
|
+
if not isinstance(
|
|
356
|
+
field_obj,
|
|
344
357
|
(
|
|
345
358
|
ManyToManyDescriptor,
|
|
346
359
|
ReverseManyToOneDescriptor,
|
|
347
360
|
ReverseOneToOneDescriptor,
|
|
361
|
+
ForwardManyToOneDescriptor,
|
|
362
|
+
ForwardOneToOneDescriptor,
|
|
348
363
|
),
|
|
349
364
|
):
|
|
350
|
-
|
|
351
|
-
rel_obj: ModelSerializer = rel_f_obj.field.related_model
|
|
352
|
-
if rel_f_obj.reverse:
|
|
353
|
-
rel_obj = rel_f_obj.field.model
|
|
354
|
-
elif isinstance(rel_f_obj, ReverseManyToOneDescriptor):
|
|
355
|
-
rel_obj = rel_f_obj.field.model
|
|
356
|
-
else: # ReverseOneToOneDescriptor
|
|
357
|
-
rel_obj = rel_f_obj.related.related_model
|
|
358
|
-
if not rel_obj == cls:
|
|
359
|
-
continue
|
|
360
|
-
cls_f.append(rel_f)
|
|
361
|
-
obj.ReadSerializer.fields.remove(rel_f)
|
|
362
|
-
rel_schema = obj.generate_read_s(depth=0)
|
|
363
|
-
rel_data = (
|
|
364
|
-
field,
|
|
365
|
-
rel_schema | None,
|
|
366
|
-
None,
|
|
367
|
-
)
|
|
368
|
-
if len(cls_f) > 0:
|
|
369
|
-
obj.ReadSerializer.fields.append(*cls_f)
|
|
370
|
-
return rel_data
|
|
365
|
+
_related_fields.append(f)
|
|
371
366
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
for
|
|
378
|
-
|
|
379
|
-
if (
|
|
380
|
-
isinstance(
|
|
381
|
-
rel_f_obj.field,
|
|
382
|
-
(
|
|
383
|
-
models.ForeignKey,
|
|
384
|
-
models.OneToOneField,
|
|
385
|
-
),
|
|
386
|
-
)
|
|
387
|
-
and rel_f_obj.field.related_model == cls
|
|
388
|
-
):
|
|
389
|
-
cls_f.append(rel_f)
|
|
390
|
-
obj.ReadSerializer.fields.remove(rel_f)
|
|
391
|
-
continue
|
|
392
|
-
if isinstance(rel_f_obj.field, models.ManyToManyField):
|
|
393
|
-
cls_f.append(rel_f)
|
|
394
|
-
obj.ReadSerializer.fields.remove(rel_f)
|
|
395
|
-
|
|
396
|
-
rel_schema = obj.generate_read_s(depth=0)
|
|
397
|
-
if rel_type == "many":
|
|
398
|
-
rel_schema = list[rel_schema]
|
|
399
|
-
rel_data = (
|
|
400
|
-
field,
|
|
401
|
-
rel_schema | None,
|
|
402
|
-
None,
|
|
403
|
-
)
|
|
404
|
-
if len(cls_f) > 0:
|
|
405
|
-
obj.ReadSerializer.fields.append(*cls_f)
|
|
406
|
-
return rel_data
|
|
367
|
+
if not _related_fields:
|
|
368
|
+
return None, None
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
custom_related_fields = [(f, *custom_f[f]) for f in _related_fields if f in custom_f]
|
|
372
|
+
related_fields = [f for f in _related_fields if f not in custom_f]
|
|
373
|
+
return related_fields, custom_related_fields
|
|
407
374
|
|
|
408
375
|
@classmethod
|
|
409
376
|
def get_schema_out_data(cls):
|
|
@@ -433,9 +400,16 @@ class ModelSerializer(models.Model, metaclass=ModelSerializerMeta):
|
|
|
433
400
|
rel_type = "one"
|
|
434
401
|
if not isinstance(rel_obj, ModelSerializerMeta):
|
|
435
402
|
continue
|
|
436
|
-
if not rel_obj.get_fields("read") and not rel_obj.get_custom_fields(
|
|
403
|
+
if not rel_obj.get_fields("read") and not rel_obj.get_custom_fields(
|
|
404
|
+
"read"
|
|
405
|
+
):
|
|
437
406
|
continue
|
|
438
|
-
|
|
407
|
+
rel_schema = (
|
|
408
|
+
rel_obj.generate_related_s()
|
|
409
|
+
if rel_type != "many"
|
|
410
|
+
else list[rel_obj.generate_related_s()]
|
|
411
|
+
)
|
|
412
|
+
rel_data = (f, rel_schema | None, None)
|
|
439
413
|
reverse_rels.append(rel_data)
|
|
440
414
|
continue
|
|
441
415
|
if isinstance(
|
|
@@ -445,9 +419,11 @@ class ModelSerializer(models.Model, metaclass=ModelSerializerMeta):
|
|
|
445
419
|
if not isinstance(rel_obj, ModelSerializerMeta):
|
|
446
420
|
fields.append(f)
|
|
447
421
|
continue
|
|
448
|
-
if not rel_obj.get_fields("read") and not rel_obj.get_custom_fields(
|
|
422
|
+
if not rel_obj.get_fields("read") and not rel_obj.get_custom_fields(
|
|
423
|
+
"read"
|
|
424
|
+
):
|
|
449
425
|
continue
|
|
450
|
-
rel_data =
|
|
426
|
+
rel_data = (f, rel_obj.generate_related_s() | None, None)
|
|
451
427
|
rels.append(rel_data)
|
|
452
428
|
continue
|
|
453
429
|
fields.append(f)
|
|
@@ -471,7 +447,7 @@ class ModelSerializer(models.Model, metaclass=ModelSerializerMeta):
|
|
|
471
447
|
) or cls._is_special_field("update", field, "optionals")
|
|
472
448
|
|
|
473
449
|
@classmethod
|
|
474
|
-
def get_custom_fields(cls, s_type: type[S_TYPES]):
|
|
450
|
+
def get_custom_fields(cls, s_type: type[S_TYPES]) -> list[tuple]:
|
|
475
451
|
return cls._get_fields(s_type, "customs")
|
|
476
452
|
|
|
477
453
|
@classmethod
|
|
@@ -500,3 +476,7 @@ class ModelSerializer(models.Model, metaclass=ModelSerializerMeta):
|
|
|
500
476
|
@classmethod
|
|
501
477
|
def generate_update_s(cls) -> Schema:
|
|
502
478
|
return cls._generate_model_schema("Patch")
|
|
479
|
+
|
|
480
|
+
@classmethod
|
|
481
|
+
def generate_related_s(cls) -> Schema:
|
|
482
|
+
return cls._generate_model_schema("Related")
|
ninja_aio/types.py
CHANGED
|
@@ -3,11 +3,11 @@ from typing import Literal
|
|
|
3
3
|
from django.db.models import Model
|
|
4
4
|
|
|
5
5
|
S_TYPES = Literal["read", "create", "update"]
|
|
6
|
-
REL_TYPES = Literal["many", "one"]
|
|
7
6
|
F_TYPES = Literal["fields", "customs", "optionals", "excludes"]
|
|
8
|
-
SCHEMA_TYPES = Literal["In", "Out", "Patch"]
|
|
7
|
+
SCHEMA_TYPES = Literal["In", "Out", "Patch", "Related"]
|
|
9
8
|
VIEW_TYPES = Literal["list", "retrieve", "create", "update", "delete", "all"]
|
|
10
9
|
|
|
10
|
+
|
|
11
11
|
class ModelSerializerType(type):
|
|
12
12
|
def __repr__(self):
|
|
13
13
|
return self.__name__
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
ninja_aio/__init__.py,sha256=JoQLorChXFbDL3NJNUxXJK3CvLwiBxfYk33tCvG88Uw,119
|
|
2
|
-
ninja_aio/api.py,sha256=Fe6l3YCy7MW5TY4-Lbl80CFuK2NT2Y7tHfmqPk6Mqak,1735
|
|
3
|
-
ninja_aio/auth.py,sha256=fKboioU4sezPukKJukIwiboxml_KV7irhCH3vGYt5pU,1008
|
|
4
|
-
ninja_aio/exceptions.py,sha256=gPnZX1Do2GXudbU8wDYkwhO70Qj0ZNrIJJ2UXRs9vYk,2241
|
|
5
|
-
ninja_aio/models.py,sha256=hBC5j10yFfDBcJ_UkJHYpW4Zg5r7thk6NuVYPAscMnk,17854
|
|
6
|
-
ninja_aio/parsers.py,sha256=e_4lGCPV7zs-HTqtdJTc8yQD2KPAn9njbL8nF_Mmgkc,153
|
|
7
|
-
ninja_aio/renders.py,sha256=mHeKNJtmDhZmgFpS9B6SPn5uZFcyVXrsoMhr149LeW8,1555
|
|
8
|
-
ninja_aio/schemas.py,sha256=EgRkfhnzZqwGvdBmqlZixMtMcoD1ZxV_qzJ3fmaAy20,113
|
|
9
|
-
ninja_aio/types.py,sha256=EHznS-6KWLwSX5hLeXbAi7qHWla09_rGeQraiLpH-aY,491
|
|
10
|
-
ninja_aio/views.py,sha256=qROag0OsMeVUXcnUYKV7ZmWj4E0F-QH52PI2-56zVRs,9263
|
|
11
|
-
django_ninja_aio_crud-0.7.2.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
|
|
12
|
-
django_ninja_aio_crud-0.7.2.dist-info/METADATA,sha256=ukl29NR99otzFVi0RUglUnRTg1NoVGNpqoKbGJMVIeY,13737
|
|
13
|
-
django_ninja_aio_crud-0.7.2.dist-info/RECORD,,
|