django-ninja-aio-crud 1.0.3__tar.gz → 1.0.4__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-1.0.3 → django_ninja_aio_crud-1.0.4}/PKG-INFO +1 -1
- {django_ninja_aio_crud-1.0.3 → django_ninja_aio_crud-1.0.4}/ninja_aio/__init__.py +1 -1
- {django_ninja_aio_crud-1.0.3 → django_ninja_aio_crud-1.0.4}/ninja_aio/models.py +23 -5
- {django_ninja_aio_crud-1.0.3 → django_ninja_aio_crud-1.0.4}/LICENSE +0 -0
- {django_ninja_aio_crud-1.0.3 → django_ninja_aio_crud-1.0.4}/README.md +0 -0
- {django_ninja_aio_crud-1.0.3 → django_ninja_aio_crud-1.0.4}/ninja_aio/api.py +0 -0
- {django_ninja_aio_crud-1.0.3 → django_ninja_aio_crud-1.0.4}/ninja_aio/auth.py +0 -0
- {django_ninja_aio_crud-1.0.3 → django_ninja_aio_crud-1.0.4}/ninja_aio/decorators.py +0 -0
- {django_ninja_aio_crud-1.0.3 → django_ninja_aio_crud-1.0.4}/ninja_aio/exceptions.py +0 -0
- {django_ninja_aio_crud-1.0.3 → django_ninja_aio_crud-1.0.4}/ninja_aio/helpers/__init__.py +0 -0
- {django_ninja_aio_crud-1.0.3 → django_ninja_aio_crud-1.0.4}/ninja_aio/helpers/api.py +0 -0
- {django_ninja_aio_crud-1.0.3 → django_ninja_aio_crud-1.0.4}/ninja_aio/parsers.py +0 -0
- {django_ninja_aio_crud-1.0.3 → django_ninja_aio_crud-1.0.4}/ninja_aio/renders.py +0 -0
- {django_ninja_aio_crud-1.0.3 → django_ninja_aio_crud-1.0.4}/ninja_aio/schemas.py +0 -0
- {django_ninja_aio_crud-1.0.3 → django_ninja_aio_crud-1.0.4}/ninja_aio/types.py +0 -0
- {django_ninja_aio_crud-1.0.3 → django_ninja_aio_crud-1.0.4}/ninja_aio/views.py +0 -0
- {django_ninja_aio_crud-1.0.3 → django_ninja_aio_crud-1.0.4}/pyproject.toml +0 -0
|
@@ -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 =
|
|
291
|
+
descriptor = await agetattr(self.model, field_name, None)
|
|
292
292
|
if descriptor is None:
|
|
293
293
|
return None
|
|
294
|
-
return
|
|
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
|
-
|
|
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):
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|