django-ninja-aio-crud 0.10.1__tar.gz → 0.10.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: django-ninja-aio-crud
3
- Version: 0.10.1
3
+ Version: 0.10.3
4
4
  Summary: Django Ninja AIO CRUD - Rest Framework
5
5
  Author: Giuseppe Casillo
6
6
  Requires-Python: >=3.10
@@ -1,6 +1,6 @@
1
1
  """Django Ninja AIO CRUD - Rest Framework"""
2
2
 
3
- __version__ = "0.10.1"
3
+ __version__ = "0.10.3"
4
4
 
5
5
  from .api import NinjaAIO
6
6
 
@@ -33,6 +33,10 @@ class ModelUtil:
33
33
  def serializable_fields(self):
34
34
  if isinstance(self.model, ModelSerializerMeta):
35
35
  return self.model.get_fields("read")
36
+ return self.model_fields
37
+
38
+ @property
39
+ def model_fields(self):
36
40
  return [field.name for field in self.model._meta.get_fields()]
37
41
 
38
42
  @property
@@ -106,13 +110,17 @@ class ModelUtil:
106
110
  customs = {}
107
111
  optionals = []
108
112
  if isinstance(self.model, ModelSerializerMeta):
109
- customs = {k: v for k, v in payload.items() if self.model.is_custom(k)}
113
+ customs = {
114
+ k: v
115
+ for k, v in payload.items()
116
+ if self.model.is_custom(k) and k not in self.model_fields
117
+ }
110
118
  optionals = [
111
119
  k for k, v in payload.items() if self.model.is_optional(k) and v is None
112
120
  ]
113
121
  for k, v in payload.items():
114
122
  if isinstance(self.model, ModelSerializerMeta):
115
- if self.model.is_custom(k):
123
+ if self.model.is_custom(k) and k not in self.model_fields:
116
124
  continue
117
125
  if self.model.is_optional(k) and v is None:
118
126
  continue
@@ -499,3 +499,24 @@ class APIViewSet:
499
499
  manage_related.__name__ = (
500
500
  f"manage_{self.model_util.model_name}_{rel_path}"
501
501
  )
502
+
503
+ def _add_views(self):
504
+ if "all" in self.disable:
505
+ if self.m2m_relations:
506
+ self._m2m_views()
507
+ self.views()
508
+ return self.router
509
+
510
+ for views_type, (schema, view) in self._crud_views.items():
511
+ if views_type not in self.disable and (
512
+ schema is not None or views_type == "delete"
513
+ ):
514
+ view()
515
+
516
+ self.views()
517
+ if self.m2m_relations:
518
+ self._m2m_views()
519
+ return self.router
520
+
521
+ def add_views_to_route(self):
522
+ return self.api.add_router(f"{self.api_route_path}", self._add_views())