django-ninja-aio-crud 0.11.3__tar.gz → 0.11.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.4
2
2
  Name: django-ninja-aio-crud
3
- Version: 0.11.3
3
+ Version: 0.11.4
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.11.3"
3
+ __version__ = "0.11.4"
4
4
 
5
5
  from .api import NinjaAIO
6
6
 
@@ -101,7 +101,11 @@ class APIViewSet:
101
101
  - **retrieve_docs** (`str`): Documentation for the retrieve view.
102
102
  - **update_docs** (`str`): Documentation for the update view.
103
103
  - **delete_docs** (`str`): Documentation for the delete view.
104
- - **m2m_relations** (`tuple[ModelSerializer | Model, str]`): Many-to-many relations to manage.
104
+ - **m2m_relations** (`list[tuple[ModelSerializer | Model, str, str, list]]`): Many-to-many relations to manage. Each tuple contains:
105
+ - The related model.
106
+ - The related name on the main model.
107
+ - The name of the path, if not provided a default will be used.
108
+ - The authentication for the m2m views.
105
109
  - **m2m_add** (`bool`): Enable add operation for M2M relations.
106
110
  - **m2m_remove** (`bool`): Enable remove operation for M2M relations.
107
111
  - **m2m_get** (`bool`): Enable get operation for M2M relations.
@@ -150,12 +154,11 @@ class APIViewSet:
150
154
  retrieve_docs = "Retrieve a specific object by its primary key."
151
155
  update_docs = "Update an object by its primary key."
152
156
  delete_docs = "Delete an object by its primary key."
153
- m2m_relations: list[tuple[ModelSerializer | Model, str]] = []
157
+ m2m_relations: list[tuple[ModelSerializer | Model, str, str, list]] = []
154
158
  m2m_add = True
155
159
  m2m_remove = True
156
160
  m2m_get = True
157
161
  m2m_auth: list | None = NOT_SET
158
- m2m_path: str = ""
159
162
 
160
163
  def __init__(self) -> None:
161
164
  self.error_codes = ERROR_CODES
@@ -396,12 +399,20 @@ class APIViewSet:
396
399
  return errors, objs_detail, objs
397
400
 
398
401
  def _m2m_views(self):
399
- for model, related_name in self.m2m_relations:
402
+ for m2m_data in self.m2m_relations:
403
+ m2m_auth = self.m2m_auth
404
+ if len(m2m_data) == 3:
405
+ model, related_name, m2m_path = m2m_data
406
+ elif len(m2m_data) == 4:
407
+ model, related_name, m2m_path, m2m_auth = m2m_data
408
+ else:
409
+ model, related_name = m2m_data
410
+ m2m_path = ""
400
411
  rel_util = ModelUtil(model)
401
412
  rel_path = (
402
413
  rel_util.verbose_name_path_resolver()
403
- if not self.m2m_path
404
- else self.m2m_path
414
+ if not m2m_path
415
+ else m2m_path
405
416
  )
406
417
  if self.m2m_get:
407
418
 
@@ -411,7 +422,7 @@ class APIViewSet:
411
422
  200: List[model.generate_related_s(),],
412
423
  self.error_codes: GenericMessageSchema,
413
424
  },
414
- auth=self.m2m_auth,
425
+ auth=m2m_auth,
415
426
  summary=f"Get {rel_util.model._meta.verbose_name_plural.capitalize()}",
416
427
  description=f"Get all related {rel_util.model._meta.verbose_name_plural.capitalize()}",
417
428
  )
@@ -446,7 +457,7 @@ class APIViewSet:
446
457
  200: M2MSchemaOut,
447
458
  self.error_codes: GenericMessageSchema,
448
459
  },
449
- auth=self.m2m_auth,
460
+ auth=m2m_auth,
450
461
  summary=summary,
451
462
  description=description,
452
463
  )