django-ninja-aio-crud 2.14.0__py3-none-any.whl → 2.15.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.

Potentially problematic release.


This version of django-ninja-aio-crud might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: django-ninja-aio-crud
3
- Version: 2.14.0
3
+ Version: 2.15.0
4
4
  Summary: Django Ninja AIO CRUD - Rest Framework
5
5
  Author: Giuseppe Casillo
6
6
  Requires-Python: >=3.10, <3.15
@@ -1,4 +1,4 @@
1
- ninja_aio/__init__.py,sha256=cdoKMOyGNe8UDjxTJQBqIMhJ_-OLa8J5FBMGB-6C-6E,120
1
+ ninja_aio/__init__.py,sha256=1ZReAODrup4BI5sHOAuanMqhDqfl36W8gVvhBrf5IZ0,120
2
2
  ninja_aio/api.py,sha256=tuC7vdvn7s1GkCnSFy9Kn1zv0glZfYptRQVvo8ZRtGQ,2429
3
3
  ninja_aio/auth.py,sha256=4sWdFPjKiQgUL1d_CSGDblVjnY5ptP6LQha6XXdluJA,9157
4
4
  ninja_aio/exceptions.py,sha256=_3xFqfFCOfrrMhSA0xbMqgXy8R0UQjhXaExrFvaDAjY,3891
@@ -14,7 +14,7 @@ ninja_aio/helpers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
14
14
  ninja_aio/helpers/api.py,sha256=O2nGvP3VSsG-AReQRn90yDH8vS3kMKh125j-ikwgGoQ,20987
15
15
  ninja_aio/helpers/query.py,sha256=Lqv4nrWYr543tC5K-SEcBottLID8cb83aDc26i2Wxj4,5053
16
16
  ninja_aio/models/__init__.py,sha256=L3UQnQAlKoI3F7jinadL-Nn55hkPvnSRPYW0JtnbWFo,114
17
- ninja_aio/models/serializers.py,sha256=Bv5Guqc_OuOGPos6A8HD0EdfGJZI_NQ9mmHhKb8jyZI,42114
17
+ ninja_aio/models/serializers.py,sha256=tm2ACQO-n877NTYN0YR-6qVZrZQpWgPDh0EeOZo_TWY,42824
18
18
  ninja_aio/models/utils.py,sha256=lAXtc3YY7_n4f0jIacX4DSXhUOzMy7y5MsBnInNxtfk,32874
19
19
  ninja_aio/schemas/__init__.py,sha256=dHILiYBKMb51lDcyQdiXRw_0nzqM7Lu81UX2hv7kEfo,837
20
20
  ninja_aio/schemas/api.py,sha256=dGUpJXR1iAf93QNR4kYj1uqIkTjiMfXultCotY6GtaQ,361
@@ -24,7 +24,7 @@ ninja_aio/schemas/helpers.py,sha256=h4zQRf21NVLMQbIVH-psAE4FICUBc857EqngblEy7og,
24
24
  ninja_aio/views/__init__.py,sha256=DEzjWA6y3WF0V10nNF8eEurLNEodgxKzyFd09AqVp3s,148
25
25
  ninja_aio/views/api.py,sha256=AAqkj0xT8J3PmJvsbluZ33cfrmrXJHiV9ARe2BqnfQ8,22492
26
26
  ninja_aio/views/mixins.py,sha256=Zl6J8gbVagwT85bzDuKyJTk3iFxxFgX0YgYkjiUxZGg,17040
27
- django_ninja_aio_crud-2.14.0.dist-info/licenses/LICENSE,sha256=yrDAYcm0gRp_Qyzo3GQa4BjYjWRkAhGC8QRva__RYq0,1073
28
- django_ninja_aio_crud-2.14.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
29
- django_ninja_aio_crud-2.14.0.dist-info/METADATA,sha256=M2D8ZIAziKDs1Xo2AibR1QzcTXXe2Tlxeh3h7CYi6bo,9964
30
- django_ninja_aio_crud-2.14.0.dist-info/RECORD,,
27
+ django_ninja_aio_crud-2.15.0.dist-info/licenses/LICENSE,sha256=yrDAYcm0gRp_Qyzo3GQa4BjYjWRkAhGC8QRva__RYq0,1073
28
+ django_ninja_aio_crud-2.15.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
29
+ django_ninja_aio_crud-2.15.0.dist-info/METADATA,sha256=m89g4FLCQgQvwCkSoJLxzsUwCuf4ESwyqKJLX31qKAo,9964
30
+ django_ninja_aio_crud-2.15.0.dist-info/RECORD,,
ninja_aio/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  """Django Ninja AIO CRUD - Rest Framework"""
2
2
 
3
- __version__ = "2.14.0"
3
+ __version__ = "2.15.0"
4
4
 
5
5
  from .api import NinjaAIO
6
6
 
@@ -46,8 +46,23 @@ def _extract_pk(v: Any) -> Any:
46
46
  return v
47
47
 
48
48
 
49
- # Annotated type for extracting PK from model instances during serialization
50
- PkFromModel = Annotated[int, BeforeValidator(_extract_pk)]
49
+ class PkFromModel:
50
+ """Subscriptable type for extracting PK from model instances during serialization.
51
+
52
+ Usage:
53
+ PkFromModel[int] -> for integer PKs
54
+ PkFromModel[str] -> for string PKs
55
+ PkFromModel[UUID] -> for UUID PKs
56
+ PkFromModel -> defaults to int (backwards compatible)
57
+ """
58
+
59
+ _default = Annotated[int, BeforeValidator(_extract_pk)]
60
+
61
+ def __class_getitem__(cls, pk_type: type) -> type:
62
+ return Annotated[pk_type, BeforeValidator(_extract_pk)]
63
+
64
+ def __new__(cls):
65
+ return cls._default
51
66
 
52
67
 
53
68
  class BaseSerializer:
@@ -415,12 +430,14 @@ class BaseSerializer:
415
430
 
416
431
  # Handle relations_as_id for reverse relations
417
432
  if field_name in relations_as_id:
433
+ from ninja_aio.models.utils import ModelUtil
434
+ pk_field_type = ModelUtil(rel_model).pk_field_type
418
435
  if many:
419
436
  # For many relations, use PkFromModel to extract PKs from model instances
420
- return (field_name, list[PkFromModel], Field(default_factory=list))
437
+ return (field_name, list[PkFromModel[pk_field_type]], Field(default_factory=list))
421
438
  else:
422
439
  # For single reverse relations (ReverseOneToOne), extract pk
423
- return (field_name, PkFromModel | None, None)
440
+ return (field_name, PkFromModel[pk_field_type] | None, None)
424
441
 
425
442
  schema = cls._resolve_relation_schema(field_name, rel_model)
426
443
  if not schema:
@@ -455,8 +472,10 @@ class BaseSerializer:
455
472
 
456
473
  # Handle relations_as_id: serialize as the raw FK ID
457
474
  if field_name in relations_as_id:
475
+ from ninja_aio.models.utils import ModelUtil
476
+ pk_field_type = ModelUtil(rel_model).pk_field_type
458
477
  # Use PkFromModel to extract pk from the related instance during serialization
459
- return (field_name, PkFromModel | None, None)
478
+ return (field_name, PkFromModel[pk_field_type] | None, None)
460
479
 
461
480
  # Special case: ModelSerializer with no readable fields should be skipped entirely
462
481
  if isinstance(rel_model, ModelSerializerMeta):