django-ninja-aio-crud 0.8.0__tar.gz → 0.8.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: django-ninja-aio-crud
3
- Version: 0.8.0
3
+ Version: 0.8.1
4
4
  Summary: Django Ninja AIO CRUD - Rest Framework
5
5
  Author: Giuseppe Casillo
6
6
  Requires-Python: >=3.10
@@ -138,7 +138,7 @@ class Foo(ModelSerializer):
138
138
 
139
139
  - post create method is a custom method that comes out to handle actions which will be excuted after that the object is created. It can be used, indeed, for example to handle custom fields' actions.
140
140
 
141
- - You can also define optional fields for you Create and Update serializers (remember to give your optional fields a default). To declare an optional fields you have to give the field type too.
141
+ - You can also define optional fields for you Create and Update serializers. To declare an optional fields you have to give the field type too.
142
142
  ```python
143
143
  # models.py
144
144
  from django.db import models
@@ -213,12 +213,13 @@ class Foo(ModelSerializer):
213
213
  excludes = ["id", "name"]
214
214
  optionals = [("bar", str), ("active", bool)]
215
215
  ```
216
- - ModelSerializer comes out also with methods executed on object save, them are:
216
+ - ModelSerializer comes out also with methods executed on object save and delete, them are:
217
217
 
218
218
  1. on_create_before_save: code executed on object creation but before saving;
219
219
  1. on_create_after_save: code executed on object creation but after saving;
220
220
  1. before_save: code executed on every save but before saving;
221
221
  1. after_save: code executed on every save but after saving;
222
+ 1. on_delete: code executed after object delete;
222
223
 
223
224
 
224
225
  ### APIViewSet
@@ -106,7 +106,7 @@ class Foo(ModelSerializer):
106
106
 
107
107
  - post create method is a custom method that comes out to handle actions which will be excuted after that the object is created. It can be used, indeed, for example to handle custom fields' actions.
108
108
 
109
- - You can also define optional fields for you Create and Update serializers (remember to give your optional fields a default). To declare an optional fields you have to give the field type too.
109
+ - You can also define optional fields for you Create and Update serializers. To declare an optional fields you have to give the field type too.
110
110
  ```python
111
111
  # models.py
112
112
  from django.db import models
@@ -181,12 +181,13 @@ class Foo(ModelSerializer):
181
181
  excludes = ["id", "name"]
182
182
  optionals = [("bar", str), ("active", bool)]
183
183
  ```
184
- - ModelSerializer comes out also with methods executed on object save, them are:
184
+ - ModelSerializer comes out also with methods executed on object save and delete, them are:
185
185
 
186
186
  1. on_create_before_save: code executed on object creation but before saving;
187
187
  1. on_create_after_save: code executed on object creation but after saving;
188
188
  1. before_save: code executed on every save but before saving;
189
189
  1. after_save: code executed on every save but after saving;
190
+ 1. on_delete: code executed after object delete;
190
191
 
191
192
 
192
193
  ### APIViewSet
@@ -1,6 +1,6 @@
1
1
  """Django Ninja AIO CRUD - Rest Framework"""
2
2
 
3
- __version__ = "0.8.0"
3
+ __version__ = "0.8.1"
4
4
 
5
5
  from .api import NinjaAIO
6
6
 
@@ -95,7 +95,7 @@ class ModelUtil:
95
95
  return reverse_rels
96
96
 
97
97
  async def parse_input_data(self, request: HttpRequest, data: Schema):
98
- payload = data.model_dump()
98
+ payload = data.model_dump(mode="json")
99
99
  customs = {}
100
100
  optionals = []
101
101
  if isinstance(self.model, ModelSerializerMeta):
@@ -128,7 +128,7 @@ class ModelUtil:
128
128
 
129
129
  async def parse_output_data(self, request: HttpRequest, data: Schema):
130
130
  olds_k: list[dict] = []
131
- payload = data.model_dump()
131
+ payload = data.model_dump(mode="json")
132
132
  for k, v in payload.items():
133
133
  try:
134
134
  field_obj = (await agetattr(self.model, k)).field
@@ -1,4 +1,5 @@
1
1
  import base64
2
+ from ipaddress import IPv4Address, IPv6Address
2
3
 
3
4
  import orjson
4
5
  from django.http import HttpRequest
@@ -31,16 +32,23 @@ class ORJSONRenderer(BaseRenderer):
31
32
  for k, v in data.items():
32
33
  if isinstance(v, bytes):
33
34
  data |= {k: base64.b64encode(v).decode()}
35
+ continue
36
+ if isinstance(v, (IPv4Address, IPv6Address)):
37
+ data |= {k: str(v)}
38
+ continue
34
39
  if isinstance(v, dict):
35
40
  for k_rel, v_rel in v.items():
36
- if not isinstance(v_rel, bytes):
37
- continue
38
- v |= {k_rel: base64.b64encode(v_rel).decode()}
41
+ if isinstance(v_rel, bytes):
42
+ v |= {k_rel: base64.b64encode(v_rel).decode()}
43
+ if isinstance(v_rel, (IPv4Address, IPv6Address)):
44
+ v |= {k_rel: str(v_rel)}
39
45
  data |= {k: v}
40
46
  if isinstance(v, list):
41
47
  for index_rel, f_rel in enumerate(v):
42
48
  for k_rel, v_rel in f_rel.items():
43
49
  if isinstance(v_rel, bytes):
44
50
  v[index_rel] |= {k_rel: base64.b64encode(v_rel).decode()}
51
+ if isinstance(v_rel, (IPv4Address, IPv6Address)):
52
+ v[index_rel] |= {k_rel: str(v_rel)}
45
53
  data |= {k: v}
46
54
  return data