django-ninja-aio-crud 0.7.2__tar.gz → 0.7.3__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.3/LICENSE +21 -0
- {django_ninja_aio_crud-0.7.2 → django_ninja_aio_crud-0.7.3}/PKG-INFO +3 -2
- {django_ninja_aio_crud-0.7.2 → django_ninja_aio_crud-0.7.3}/ninja_aio/__init__.py +1 -1
- {django_ninja_aio_crud-0.7.2 → django_ninja_aio_crud-0.7.3}/ninja_aio/models.py +52 -68
- {django_ninja_aio_crud-0.7.2 → django_ninja_aio_crud-0.7.3}/ninja_aio/types.py +2 -2
- {django_ninja_aio_crud-0.7.2 → django_ninja_aio_crud-0.7.3}/README.md +0 -0
- {django_ninja_aio_crud-0.7.2 → django_ninja_aio_crud-0.7.3}/ninja_aio/api.py +0 -0
- {django_ninja_aio_crud-0.7.2 → django_ninja_aio_crud-0.7.3}/ninja_aio/auth.py +0 -0
- {django_ninja_aio_crud-0.7.2 → django_ninja_aio_crud-0.7.3}/ninja_aio/exceptions.py +0 -0
- {django_ninja_aio_crud-0.7.2 → django_ninja_aio_crud-0.7.3}/ninja_aio/parsers.py +0 -0
- {django_ninja_aio_crud-0.7.2 → django_ninja_aio_crud-0.7.3}/ninja_aio/renders.py +0 -0
- {django_ninja_aio_crud-0.7.2 → django_ninja_aio_crud-0.7.3}/ninja_aio/schemas.py +0 -0
- {django_ninja_aio_crud-0.7.2 → django_ninja_aio_crud-0.7.3}/ninja_aio/views.py +0 -0
- {django_ninja_aio_crud-0.7.2 → django_ninja_aio_crud-0.7.3}/pyproject.toml +0 -0
|
@@ -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.
|
|
@@ -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.3
|
|
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
|
|
@@ -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,35 @@ 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 = [f[0] for f in cls.get_custom_fields("read")]
|
|
352
|
+
related_fields = []
|
|
353
|
+
for f in fields + custom_f:
|
|
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
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
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
|
+
custom_related_fields = []
|
|
371
|
+
for f in related_fields:
|
|
372
|
+
for custom in cls.get_custom_fields("read"):
|
|
373
|
+
if f == custom[0]:
|
|
374
|
+
custom_related_fields.append(custom)
|
|
375
|
+
related_fields.remove(f)
|
|
376
|
+
|
|
377
|
+
return related_fields, custom_related_fields
|
|
407
378
|
|
|
408
379
|
@classmethod
|
|
409
380
|
def get_schema_out_data(cls):
|
|
@@ -433,9 +404,16 @@ class ModelSerializer(models.Model, metaclass=ModelSerializerMeta):
|
|
|
433
404
|
rel_type = "one"
|
|
434
405
|
if not isinstance(rel_obj, ModelSerializerMeta):
|
|
435
406
|
continue
|
|
436
|
-
if not rel_obj.get_fields("read") and not rel_obj.get_custom_fields(
|
|
407
|
+
if not rel_obj.get_fields("read") and not rel_obj.get_custom_fields(
|
|
408
|
+
"read"
|
|
409
|
+
):
|
|
437
410
|
continue
|
|
438
|
-
|
|
411
|
+
rel_schema = (
|
|
412
|
+
rel_obj.generate_related_s()
|
|
413
|
+
if rel_type != "many"
|
|
414
|
+
else list[rel_obj.generate_related_s()]
|
|
415
|
+
)
|
|
416
|
+
rel_data = (f, rel_schema | None, None)
|
|
439
417
|
reverse_rels.append(rel_data)
|
|
440
418
|
continue
|
|
441
419
|
if isinstance(
|
|
@@ -445,9 +423,11 @@ class ModelSerializer(models.Model, metaclass=ModelSerializerMeta):
|
|
|
445
423
|
if not isinstance(rel_obj, ModelSerializerMeta):
|
|
446
424
|
fields.append(f)
|
|
447
425
|
continue
|
|
448
|
-
if not rel_obj.get_fields("read") and not rel_obj.get_custom_fields(
|
|
426
|
+
if not rel_obj.get_fields("read") and not rel_obj.get_custom_fields(
|
|
427
|
+
"read"
|
|
428
|
+
):
|
|
449
429
|
continue
|
|
450
|
-
rel_data =
|
|
430
|
+
rel_data = (f, rel_obj.generate_related_s() | None, None)
|
|
451
431
|
rels.append(rel_data)
|
|
452
432
|
continue
|
|
453
433
|
fields.append(f)
|
|
@@ -471,7 +451,7 @@ class ModelSerializer(models.Model, metaclass=ModelSerializerMeta):
|
|
|
471
451
|
) or cls._is_special_field("update", field, "optionals")
|
|
472
452
|
|
|
473
453
|
@classmethod
|
|
474
|
-
def get_custom_fields(cls, s_type: type[S_TYPES]):
|
|
454
|
+
def get_custom_fields(cls, s_type: type[S_TYPES]) -> list[tuple]:
|
|
475
455
|
return cls._get_fields(s_type, "customs")
|
|
476
456
|
|
|
477
457
|
@classmethod
|
|
@@ -500,3 +480,7 @@ class ModelSerializer(models.Model, metaclass=ModelSerializerMeta):
|
|
|
500
480
|
@classmethod
|
|
501
481
|
def generate_update_s(cls) -> Schema:
|
|
502
482
|
return cls._generate_model_schema("Patch")
|
|
483
|
+
|
|
484
|
+
@classmethod
|
|
485
|
+
def generate_related_s(cls) -> Schema:
|
|
486
|
+
return cls._generate_model_schema("Related")
|
|
@@ -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__
|
|
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
|