django-ninja-aio-crud 0.6.2__tar.gz → 0.6.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: django-ninja-aio-crud
3
- Version: 0.6.2
3
+ Version: 0.6.4
4
4
  Summary: Django Ninja AIO CRUD - Rest Framework
5
5
  Author: Giuseppe Casillo
6
6
  Requires-Python: >=3.10
@@ -196,7 +196,7 @@ class Foo(ModelSerializer):
196
196
  bar = models.CharField(max_length=30, default="")
197
197
  active = models.BooleanField(default=False)
198
198
 
199
- @propetry
199
+ @property
200
200
  def full_name(self):
201
201
  return f"{self.name} example_full_name"
202
202
 
@@ -472,7 +472,7 @@ api = NinjaAIO()
472
472
  class FooAPI(APIViewSet):
473
473
  model = Foo
474
474
  api = api
475
- auths = CustomJWTBearer()
475
+ auth = CustomJWTBearer()
476
476
 
477
477
 
478
478
  class ExampleSchemaOut(Schema):
@@ -488,10 +488,10 @@ class SumView(APIView):
488
488
  api = api
489
489
  api_router_path = "numbers-sum/"
490
490
  router_tag = "Sum"
491
- auths = CustomJWTBearer()
491
+ auth = CustomJWTBearer()
492
492
 
493
493
  def views(self):
494
- @self.router.post("/", response={200: ExampleSchemaOut}, auth=self.auths)
494
+ @self.router.post("/", response={200: ExampleSchemaOut}, auth=self.auth)
495
495
  async def sum(request: HttpRequest, data: ExampleSchemaIn):
496
496
  return 200, {sum: data.n1 + data.n2}
497
497
 
@@ -165,7 +165,7 @@ class Foo(ModelSerializer):
165
165
  bar = models.CharField(max_length=30, default="")
166
166
  active = models.BooleanField(default=False)
167
167
 
168
- @propetry
168
+ @property
169
169
  def full_name(self):
170
170
  return f"{self.name} example_full_name"
171
171
 
@@ -441,7 +441,7 @@ api = NinjaAIO()
441
441
  class FooAPI(APIViewSet):
442
442
  model = Foo
443
443
  api = api
444
- auths = CustomJWTBearer()
444
+ auth = CustomJWTBearer()
445
445
 
446
446
 
447
447
  class ExampleSchemaOut(Schema):
@@ -457,10 +457,10 @@ class SumView(APIView):
457
457
  api = api
458
458
  api_router_path = "numbers-sum/"
459
459
  router_tag = "Sum"
460
- auths = CustomJWTBearer()
460
+ auth = CustomJWTBearer()
461
461
 
462
462
  def views(self):
463
- @self.router.post("/", response={200: ExampleSchemaOut}, auth=self.auths)
463
+ @self.router.post("/", response={200: ExampleSchemaOut}, auth=self.auth)
464
464
  async def sum(request: HttpRequest, data: ExampleSchemaIn):
465
465
  return 200, {sum: data.n1 + data.n2}
466
466
 
@@ -1,6 +1,6 @@
1
1
  """Django Ninja AIO CRUD - Rest Framework"""
2
2
 
3
- __version__ = "0.6.2"
3
+ __version__ = "0.6.4"
4
4
 
5
5
  from .api import NinjaAIO
6
6
 
@@ -51,13 +51,14 @@ class ModelUtil:
51
51
  pk: int | str = None,
52
52
  filters: dict = None,
53
53
  getters: dict = None,
54
+ with_qs_request=True,
54
55
  ):
55
56
  get_q = {self.model_pk_name: pk} if pk is not None else {}
56
57
  if getters:
57
58
  get_q |= getters
58
59
 
59
60
  obj_qs = self.model.objects.select_related()
60
- if isinstance(self.model, ModelSerializerMeta):
61
+ if isinstance(self.model, ModelSerializerMeta) and with_qs_request:
61
62
  obj_qs = await self.model.queryset_request(request)
62
63
 
63
64
  obj_qs = obj_qs.prefetch_related(*self.get_reverse_relations())
@@ -108,7 +109,9 @@ class ModelUtil:
108
109
  raise SerializeError({k: ". ".join(exc.args)}, 400)
109
110
  if isinstance(field_obj, models.ForeignKey):
110
111
  rel_util = ModelUtil(field_obj.related_model)
111
- rel: ModelSerializer = await rel_util.get_object(request, v)
112
+ rel: ModelSerializer = await rel_util.get_object(
113
+ request, v, with_qs_request=False
114
+ )
112
115
  payload |= {k: rel}
113
116
  new_payload = {
114
117
  k: v for k, v in payload.items() if k not in (customs.keys() or optionals)
@@ -132,7 +135,7 @@ class ModelUtil:
132
135
  ):
133
136
  rel_util = ModelUtil(field_obj.related_model)
134
137
  rel: ModelSerializer = await rel_util.get_object(
135
- request, list(v.values())[0]
138
+ request, list(v.values())[0], with_qs_request=False
136
139
  )
137
140
  if isinstance(field_obj, models.ForeignKey):
138
141
  for rel_k, rel_v in v.items():
@@ -18,7 +18,7 @@ class APIView:
18
18
  api: NinjaAPI
19
19
  router_tag: str
20
20
  api_route_path: str
21
- auths: list | None = NOT_SET
21
+ auth: list | None = NOT_SET
22
22
 
23
23
  def __init__(self) -> None:
24
24
  self.router = Router(tags=[self.router_tag])
@@ -71,7 +71,7 @@ class APIViewSet:
71
71
  schema_in: Schema | None = None
72
72
  schema_out: Schema | None = None
73
73
  schema_update: Schema | None = None
74
- auths: list | None = NOT_SET
74
+ auth: list | None = NOT_SET
75
75
  pagination_class: type[AsyncPaginationBase] = PageNumberPagination
76
76
  query_params: dict[str, tuple[type, ...]] = {}
77
77
  disable: list[type[VIEW_TYPES]] = []
@@ -137,7 +137,7 @@ class APIViewSet:
137
137
  def create_view(self):
138
138
  @self.router.post(
139
139
  self.path,
140
- auth=self.auths,
140
+ auth=self.auth,
141
141
  response={201: self.schema_out, self.error_codes: GenericMessageSchema},
142
142
  )
143
143
  async def create(request: HttpRequest, data: self.schema_in):
@@ -149,7 +149,7 @@ class APIViewSet:
149
149
  def list_view(self):
150
150
  @self.router.get(
151
151
  self.path,
152
- auth=self.auths,
152
+ auth=self.auth,
153
153
  response={
154
154
  200: List[self.schema_out],
155
155
  self.error_codes: GenericMessageSchema,
@@ -179,7 +179,7 @@ class APIViewSet:
179
179
  def retrieve_view(self):
180
180
  @self.router.get(
181
181
  self.path_retrieve,
182
- auth=self.auths,
182
+ auth=self.auth,
183
183
  response={200: self.schema_out, self.error_codes: GenericMessageSchema},
184
184
  )
185
185
  async def retrieve(request: HttpRequest, pk: Path[self.path_schema]):
@@ -192,7 +192,7 @@ class APIViewSet:
192
192
  def update_view(self):
193
193
  @self.router.patch(
194
194
  self.path_retrieve,
195
- auth=self.auths,
195
+ auth=self.auth,
196
196
  response={200: self.schema_out, self.error_codes: GenericMessageSchema},
197
197
  )
198
198
  async def update(
@@ -208,7 +208,7 @@ class APIViewSet:
208
208
  def delete_view(self):
209
209
  @self.router.delete(
210
210
  self.path_retrieve,
211
- auth=self.auths,
211
+ auth=self.auth,
212
212
  response={204: None, self.error_codes: GenericMessageSchema},
213
213
  )
214
214
  async def delete(request: HttpRequest, pk: Path[self.path_schema]):