django-ninja-aio-crud 1.0.3__py3-none-any.whl → 1.0.5__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: django-ninja-aio-crud
3
- Version: 1.0.3
3
+ Version: 1.0.5
4
4
  Summary: Django Ninja AIO CRUD - Rest Framework
5
5
  Author: Giuseppe Casillo
6
6
  Requires-Python: >=3.10
@@ -23,9 +23,9 @@ Classifier: Framework :: AsyncIO
23
23
  Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
24
24
  Classifier: Topic :: Internet :: WWW/HTTP
25
25
  License-File: LICENSE
26
- Requires-Dist: django-ninja >=1.3.0
27
- Requires-Dist: joserfc >=1.0.0
28
- Requires-Dist: orjson >= 3.10.7
26
+ Requires-Dist: django-ninja >=1.3.0, <=1.4.5
27
+ Requires-Dist: joserfc >=1.0.0, <= 1.4.1
28
+ Requires-Dist: orjson >= 3.10.7, <= 3.11.4
29
29
  Requires-Dist: coverage ; extra == "test"
30
30
  Project-URL: Documentation, https://django-ninja-aio.com
31
31
  Project-URL: Repository, https://github.com/caspel26/django-ninja-aio-crud
@@ -1,9 +1,9 @@
1
- ninja_aio/__init__.py,sha256=wwki9IvFvW3fGlR--9braYcHTw1vHiGZWTZzMaYW4VE,119
1
+ ninja_aio/__init__.py,sha256=_Euc356-ScYsaVY9gvZ7xLRgTfnHKXk0pv69eFhjdJg,119
2
2
  ninja_aio/api.py,sha256=Fe6l3YCy7MW5TY4-Lbl80CFuK2NT2Y7tHfmqPk6Mqak,1735
3
3
  ninja_aio/auth.py,sha256=zUwruKcz7MXuOnWp5k1CCSwEc8s2Lyqqk7Qm9kPbJ3o,5149
4
4
  ninja_aio/decorators.py,sha256=LsvHbMxmw_So8NV0ey5NRRvSbfYkOZLeLQ4Fix7rQAY,5519
5
5
  ninja_aio/exceptions.py,sha256=1-iRbrloIyi0CR6Tcrn5YR4_LloA7PPohKIBaxXJ0-8,2596
6
- ninja_aio/models.py,sha256=tFhMMr4avx5OtCU3-HlGOFD8cSx_t00x9aTmn3coTxw,34645
6
+ ninja_aio/models.py,sha256=fsFYjKFZb8MDpE1g3Nte-Dot4x7ofmuxIDi8qtkWu0o,35422
7
7
  ninja_aio/parsers.py,sha256=e_4lGCPV7zs-HTqtdJTc8yQD2KPAn9njbL8nF_Mmgkc,153
8
8
  ninja_aio/renders.py,sha256=5TdSQI8e4x3Gb2tAw1AaxrbU-asVjf2chWMr8x2Tt80,1485
9
9
  ninja_aio/schemas.py,sha256=sYxhovFq6nE_Gdx_yl1ufcuHBAXxpsnBmNytyTSqFLI,2449
@@ -11,7 +11,7 @@ ninja_aio/types.py,sha256=TJSGlA7bt4g9fvPhJ7gzH5tKbLagPmZUzfgttEOp4xs,468
11
11
  ninja_aio/views.py,sha256=31pyOzABHwO1jcIVJRHXVrpMu9__FHmdX2vEhX6XrPs,15890
12
12
  ninja_aio/helpers/__init__.py,sha256=E45h2prtpCudx_bSKkIDMNK9oxrHPDJrweXWCuLxUOs,59
13
13
  ninja_aio/helpers/api.py,sha256=VW5C4hQl2flYhGPgVJ2ZkFK1tGMdNOaxVWJfZfLd7OY,17171
14
- django_ninja_aio_crud-1.0.3.dist-info/licenses/LICENSE,sha256=yrDAYcm0gRp_Qyzo3GQa4BjYjWRkAhGC8QRva__RYq0,1073
15
- django_ninja_aio_crud-1.0.3.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
16
- django_ninja_aio_crud-1.0.3.dist-info/METADATA,sha256=QUPAzuNbc0o5uH6ZSd-jxlRBdh_0U4HKf8ZoLUyusK8,8540
17
- django_ninja_aio_crud-1.0.3.dist-info/RECORD,,
14
+ django_ninja_aio_crud-1.0.5.dist-info/licenses/LICENSE,sha256=yrDAYcm0gRp_Qyzo3GQa4BjYjWRkAhGC8QRva__RYq0,1073
15
+ django_ninja_aio_crud-1.0.5.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
16
+ django_ninja_aio_crud-1.0.5.dist-info/METADATA,sha256=V6cJgV_yDqLnEtG1FKbQR0fdmGE6okwPChkwEkyfNzs,8570
17
+ django_ninja_aio_crud-1.0.5.dist-info/RECORD,,
ninja_aio/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  """Django Ninja AIO CRUD - Rest Framework"""
2
2
 
3
- __version__ = "1.0.3"
3
+ __version__ = "1.0.5"
4
4
 
5
5
  from .api import NinjaAIO
6
6
 
ninja_aio/models.py CHANGED
@@ -284,14 +284,14 @@ class ModelUtil:
284
284
  rel = await rel_util.get_object(request, v, with_qs_request=False)
285
285
  payload[k] = rel
286
286
 
287
- def _extract_field_obj(self, field_name: str):
287
+ async def _extract_field_obj(self, field_name: str):
288
288
  """
289
289
  Return the underlying Django Field (if any) for a given attribute name.
290
290
  """
291
- descriptor = getattr(self.model, field_name, None)
291
+ descriptor = await agetattr(self.model, field_name, None)
292
292
  if descriptor is None:
293
293
  return None
294
- return getattr(descriptor, "field", None) or getattr(
294
+ return await agetattr(descriptor, "field", None) or await agetattr(
295
295
  descriptor, "related", None
296
296
  )
297
297
 
@@ -313,6 +313,21 @@ class ModelUtil:
313
313
  rel_pk = nested_dict.get(rel_util.model_pk_name)
314
314
  return await rel_util.get_object(request, rel_pk)
315
315
 
316
+ async def _rewrite_nested_foreign_keys(self, rel_obj, nested_dict: dict):
317
+ """
318
+ Rewrite foreign key keys inside a nested dict from <key> to <key>_id.
319
+ """
320
+ keys_to_rewrite: list[str] = []
321
+ new_nested = nested_dict
322
+ for rel_k in nested_dict.keys():
323
+ attr = await agetattr(rel_obj, rel_k)
324
+ if isinstance(attr, models.ForeignKey):
325
+ keys_to_rewrite.append(rel_k)
326
+ for old_k in keys_to_rewrite:
327
+ new_nested[f"{old_k}_id"] = new_nested.pop(old_k)
328
+ return new_nested
329
+
330
+
316
331
  async def parse_input_data(self, request: HttpRequest, data: Schema):
317
332
  """
318
333
  Transform inbound schema data to a model-ready payload.
@@ -403,10 +418,13 @@ class ModelUtil:
403
418
  payload = data.model_dump(mode="json")
404
419
 
405
420
  for k, v in payload.items():
406
- field_obj = self._extract_field_obj(k)
421
+ field_obj = await self._extract_field_obj(k)
407
422
  if not self._should_process_nested(v, field_obj):
408
423
  continue
409
- payload[k] = await self._fetch_related_instance(request, field_obj, v)
424
+ rel_instance = await self._fetch_related_instance(request, field_obj, v)
425
+ if isinstance(field_obj, models.ForeignKey):
426
+ v = await self._rewrite_nested_foreign_keys(rel_instance, v)
427
+ payload[k] = rel_instance
410
428
  return payload
411
429
 
412
430
  async def create_s(self, request: HttpRequest, data: Schema, obj_schema: Schema):