django-api-admin 1.2.3__tar.gz → 1.3.0__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.
Files changed (134) hide show
  1. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/PKG-INFO +111 -44
  2. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/README.md +109 -38
  3. django_api_admin-1.3.0/assets/images/screenshot.png +0 -0
  4. django_api_admin-1.3.0/django_api_admin/API_DOCS.md +22 -0
  5. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/__init__.py +13 -3
  6. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/actions.py +8 -14
  7. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/admin_views/admin_site_views/app_index.py +21 -24
  8. django_api_admin-1.3.0/django_api_admin/admin_views/admin_site_views/app_list.py +31 -0
  9. django_api_admin-1.3.0/django_api_admin/admin_views/admin_site_views/autocomplete.py +189 -0
  10. django_api_admin-1.3.0/django_api_admin/admin_views/admin_site_views/get_authenticated_user.py +7 -0
  11. django_api_admin-1.3.0/django_api_admin/admin_views/admin_site_views/get_permissions.py +59 -0
  12. django_api_admin-1.3.0/django_api_admin/admin_views/admin_site_views/history.py +116 -0
  13. django_api_admin-1.2.3/django_api_admin/admin_views/model_admin_views/__init__.py → django_api_admin-1.3.0/django_api_admin/admin_views/admin_site_views/language_catalog.py +0 -0
  14. django_api_admin-1.3.0/django_api_admin/admin_views/admin_site_views/site_context.py +66 -0
  15. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/admin_views/admin_site_views/view_on_site.py +38 -29
  16. {django_api_admin-1.2.3/django_api_admin/admins → django_api_admin-1.3.0/django_api_admin/admin_views/model_admin_views}/__init__.py +0 -0
  17. django_api_admin-1.3.0/django_api_admin/admin_views/model_admin_views/add.py +95 -0
  18. django_api_admin-1.3.0/django_api_admin/admin_views/model_admin_views/change.py +179 -0
  19. django_api_admin-1.3.0/django_api_admin/admin_views/model_admin_views/changelist.py +266 -0
  20. django_api_admin-1.3.0/django_api_admin/admin_views/model_admin_views/delete.py +82 -0
  21. django_api_admin-1.3.0/django_api_admin/admin_views/model_admin_views/detail.py +70 -0
  22. django_api_admin-1.3.0/django_api_admin/admins/base_admin.py +502 -0
  23. django_api_admin-1.3.0/django_api_admin/admins/inline_admin.py +117 -0
  24. django_api_admin-1.3.0/django_api_admin/admins/model_admin.py +945 -0
  25. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/apps.py +4 -2
  26. django_api_admin-1.3.0/django_api_admin/bulk.py +295 -0
  27. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/changelist.py +208 -121
  28. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/checks.py +182 -311
  29. django_api_admin-1.3.0/django_api_admin/constants.py +86 -0
  30. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/decorators.py +3 -7
  31. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/exceptions.py +6 -4
  32. django_api_admin-1.3.0/django_api_admin/extensions.py +27 -0
  33. django_api_admin-1.3.0/django_api_admin/fields.py +27 -0
  34. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/filters.py +225 -149
  35. django_api_admin-1.3.0/django_api_admin/hooks.py +473 -0
  36. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/models.py +34 -60
  37. django_api_admin-1.3.0/django_api_admin/openapi.py +508 -0
  38. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/pagination.py +5 -5
  39. django_api_admin-1.3.0/django_api_admin/serializers.py +641 -0
  40. django_api_admin-1.3.0/django_api_admin/sites.py +530 -0
  41. {django_api_admin-1.2.3/django_api_admin/migrations → django_api_admin-1.3.0/django_api_admin/utils}/__init__.py +0 -0
  42. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/utils/_get_non_gfk_field.py +1 -6
  43. django_api_admin-1.3.0/django_api_admin/utils/build_q_object_from_lookup_parameters.py +11 -0
  44. django_api_admin-1.3.0/django_api_admin/utils/construct_change_message.py +64 -0
  45. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/utils/flatten.py +1 -0
  46. django_api_admin-1.3.0/django_api_admin/utils/flatten_fieldsets.py +16 -0
  47. django_api_admin-1.3.0/django_api_admin/utils/get_changed_data.py +53 -0
  48. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/utils/get_content_type_for_model.py +1 -0
  49. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/utils/get_deleted_objects.py +7 -30
  50. django_api_admin-1.3.0/django_api_admin/utils/get_field_attributes.py +58 -0
  51. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/utils/get_fields_from_path.py +1 -1
  52. django_api_admin-1.3.0/django_api_admin/utils/get_form_fields.py +44 -0
  53. django_api_admin-1.3.0/django_api_admin/utils/get_last_value_from_parameters.py +3 -0
  54. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/utils/get_related_name.py +1 -1
  55. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/utils/label_for_field.py +1 -5
  56. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/utils/lookup_spawns_duplicates.py +1 -1
  57. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/utils/model_format_dict.py +1 -0
  58. django_api_admin-1.3.0/django_api_admin/utils/model_serializer_factory.py +84 -0
  59. django_api_admin-1.3.0/django_api_admin/utils/modelserializer_defines_fields.py +4 -0
  60. django_api_admin-1.3.0/django_api_admin/utils/module_loading.py +44 -0
  61. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/utils/nested_objects.py +1 -3
  62. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/utils/prepare_lookup_value.py +3 -0
  63. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/utils/quote.py +1 -2
  64. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/utils/remove_field.py +1 -4
  65. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/utils/reverse_field_path.py +1 -1
  66. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/utils/url_params_from_lookup_dict.py +1 -0
  67. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/pyproject.toml +30 -15
  68. django_api_admin-1.3.0/tests/mock_app/actions.py +23 -0
  69. django_api_admin-1.3.0/tests/mock_app/admin.py +128 -0
  70. django_api_admin-1.3.0/tests/mock_app/fields.py +17 -0
  71. django_api_admin-1.3.0/tests/mock_app/models.py +147 -0
  72. django_api_admin-1.3.0/tests/mock_app/serializers.py +25 -0
  73. django_api_admin-1.3.0/tests/mock_app/tests.py +846 -0
  74. django_api_admin-1.3.0/tests/mock_app/urls.py +9 -0
  75. django_api_admin-1.3.0/tests/mock_app/views.py +9 -0
  76. django_api_admin-1.3.0/tests/runtests.py +452 -0
  77. django_api_admin-1.3.0/tests/test_sqlite.py +26 -0
  78. django_api_admin-1.3.0/tests/urls.py +6 -0
  79. django_api_admin-1.2.3/LICENSE-RESTFUL-ADMIN +0 -21
  80. django_api_admin-1.2.3/assets/images/screenshot.png +0 -0
  81. django_api_admin-1.2.3/django_api_admin/admin_views/admin_site_views/admin_api_root.py +0 -51
  82. django_api_admin-1.2.3/django_api_admin/admin_views/admin_site_views/admin_log.py +0 -83
  83. django_api_admin-1.2.3/django_api_admin/admin_views/admin_site_views/app_list.py +0 -36
  84. django_api_admin-1.2.3/django_api_admin/admin_views/admin_site_views/autocomplete.py +0 -166
  85. django_api_admin-1.2.3/django_api_admin/admin_views/admin_site_views/language_catalog.py +0 -98
  86. django_api_admin-1.2.3/django_api_admin/admin_views/admin_site_views/obtain_token.py +0 -95
  87. django_api_admin-1.2.3/django_api_admin/admin_views/admin_site_views/password_change.py +0 -77
  88. django_api_admin-1.2.3/django_api_admin/admin_views/admin_site_views/site_context.py +0 -27
  89. django_api_admin-1.2.3/django_api_admin/admin_views/admin_site_views/token_refresh.py +0 -7
  90. django_api_admin-1.2.3/django_api_admin/admin_views/admin_site_views/user_information.py +0 -40
  91. django_api_admin-1.2.3/django_api_admin/admin_views/model_admin_views/add.py +0 -106
  92. django_api_admin-1.2.3/django_api_admin/admin_views/model_admin_views/change.py +0 -212
  93. django_api_admin-1.2.3/django_api_admin/admin_views/model_admin_views/changelist.py +0 -176
  94. django_api_admin-1.2.3/django_api_admin/admin_views/model_admin_views/delete.py +0 -104
  95. django_api_admin-1.2.3/django_api_admin/admin_views/model_admin_views/detail.py +0 -60
  96. django_api_admin-1.2.3/django_api_admin/admin_views/model_admin_views/handle_action.py +0 -105
  97. django_api_admin-1.2.3/django_api_admin/admin_views/model_admin_views/history.py +0 -51
  98. django_api_admin-1.2.3/django_api_admin/admin_views/model_admin_views/list.py +0 -32
  99. django_api_admin-1.2.3/django_api_admin/admins/base_admin.py +0 -295
  100. django_api_admin-1.2.3/django_api_admin/admins/inline_admin.py +0 -96
  101. django_api_admin-1.2.3/django_api_admin/admins/model_admin.py +0 -604
  102. django_api_admin-1.2.3/django_api_admin/constants/field_attributes.py +0 -82
  103. django_api_admin-1.2.3/django_api_admin/constants/vars.py +0 -12
  104. django_api_admin-1.2.3/django_api_admin/declarations/functions.py +0 -305
  105. django_api_admin-1.2.3/django_api_admin/hooks.py +0 -99
  106. django_api_admin-1.2.3/django_api_admin/openapi.py +0 -325
  107. django_api_admin-1.2.3/django_api_admin/options.py +0 -287
  108. django_api_admin-1.2.3/django_api_admin/permissions.py +0 -10
  109. django_api_admin-1.2.3/django_api_admin/serializers.py +0 -407
  110. django_api_admin-1.2.3/django_api_admin/sites.py +0 -539
  111. django_api_admin-1.2.3/django_api_admin/utils/diff_helper.py +0 -52
  112. django_api_admin-1.2.3/django_api_admin/utils/force_login.py +0 -14
  113. django_api_admin-1.2.3/django_api_admin/utils/get_field_attributes.py +0 -53
  114. django_api_admin-1.2.3/django_api_admin/utils/get_form_config.py +0 -8
  115. django_api_admin-1.2.3/django_api_admin/utils/get_form_fields.py +0 -47
  116. django_api_admin-1.2.3/django_api_admin/utils/get_inline_by_field_name.py +0 -9
  117. django_api_admin-1.2.3/django_api_admin/utils/get_inlines.py +0 -54
  118. django_api_admin-1.2.3/django_api_admin/utils/validate_bulk_edits.py +0 -109
  119. django_api_admin-1.2.3/django_api_admin/utils/validate_inline_field_names.py +0 -25
  120. django_api_admin-1.2.3/django_api_admin/views/__init__.py +0 -0
  121. django_api_admin-1.2.3/django_api_admin/views/admin_views.py +0 -677
  122. django_api_admin-1.2.3/django_api_admin/views/site_views.py +0 -251
  123. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/LICENSE +0 -0
  124. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/LICENSE-DJANGO +0 -0
  125. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/assets/images/logo.png +0 -0
  126. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/admin_views/admin_site_views/__init__.py +0 -0
  127. {django_api_admin-1.2.3/django_api_admin/constants → django_api_admin-1.3.0/django_api_admin/admins}/__init__.py +0 -0
  128. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/locale/ar/LC_MESSAGES/django.po +0 -0
  129. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/migrations/0001_initial.py +0 -0
  130. {django_api_admin-1.2.3/django_api_admin/declarations → django_api_admin-1.3.0/django_api_admin/migrations}/__init__.py +0 -0
  131. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/utils/get_model_from_relation.py +0 -0
  132. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/utils/lookup_field.py +0 -0
  133. {django_api_admin-1.2.3 → django_api_admin-1.3.0}/django_api_admin/utils/model_ngettext.py +0 -0
  134. {django_api_admin-1.2.3/django_api_admin/utils → django_api_admin-1.3.0/tests/mock_app}/__init__.py +0 -0
@@ -1,23 +1,19 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: django-api-admin
3
- Version: 1.2.3
3
+ Version: 1.3.0
4
4
  Summary: A RESTful API implementation of django.contrib.admin, designed for writing custom frontends.
5
5
  Author: Muhammad Salah
6
6
  Author-email: Muhammad Salah <msbizzacc0unt@outlook.com>
7
7
  License-File: LICENSE
8
8
  License-File: LICENSE-DJANGO
9
- License-File: LICENSE-RESTFUL-ADMIN
10
9
  Classifier: Programming Language :: Python :: 3
11
10
  Classifier: License :: OSI Approved :: MIT License
12
11
  Classifier: Operating System :: OS Independent
13
12
  Requires-Dist: django
14
13
  Requires-Dist: djangorestframework
15
14
  Requires-Dist: drf-spectacular
16
- Requires-Dist: djangorestframework-simplejwt
17
- Requires-Dist: django-cors-headers ; extra == 'example'
18
- Requires-Dist: python-dotenv>=1.1.1 ; extra == 'example'
15
+ Requires-Python: >=3.12
19
16
  Project-URL: Github, https://github.com/demon-bixia/django-api-admin
20
- Provides-Extra: example
21
17
  Description-Content-Type: text/markdown
22
18
 
23
19
  <a id="readme-top"></a>
@@ -41,7 +37,7 @@ Description-Content-Type: text/markdown
41
37
  <img src="assets/images/logo.png" alt="Logo" width="300" height="300">
42
38
  </a>
43
39
 
44
- <h3 align="center">Django API Admin</h3>
40
+ <h1 align="center">Django API Admin</h1>
45
41
 
46
42
  <p align="center">
47
43
  A RESTful API implementation of django.contrib.admin, designed for writing custom frontends.
@@ -74,6 +70,8 @@ Description-Content-Type: text/markdown
74
70
  <ul>
75
71
  <li><a href="#prerequisites">Prerequisites</a></li>
76
72
  <li><a href="#installation">Installation</a></li>
73
+ <li><a href="#cors">CORS Configuration</a></li>
74
+ <li><a href="#authentication">Authentication</a></li>
77
75
  </ul>
78
76
  </li>
79
77
  <li><a href="#usage">Usage</a></li>
@@ -92,12 +90,12 @@ Description-Content-Type: text/markdown
92
90
 
93
91
  [![Product Name Screen Shot][product-screenshot]](https://github.com/demon-bixia/django-api-admin)
94
92
 
95
- The Django API Admin project is a RESTful API implementation of the `django.contrib.admin` module, designed to facilitate the creation of custom frontends. This project aims to provide developers with a robust and flexible API that mirrors the functionality of Django's built-in admin interface, allowing for seamless integration with modern web applications.
93
+ Django API Admin is a RESTful API implementation of the `django.contrib.admin` application, designed to make it easy to create custom frontends. This project aims to provide developers with a flexible API that mirrors the functionality of Django's built-in admin interface, allowing for seamless integration with modern web client interfaces.
96
94
 
97
95
  ### Key Features:
98
96
  - **RESTful API**: Offers a comprehensive API for managing Django models, enabling developers to build custom administrative interfaces.
99
97
  - **Custom Frontends**: Designed to support the development of tailored frontends that meet specific project requirements.
100
- - **Extensible and Modular**: Build with the same django.contrib.admin API, allowing for easy customization and integration with existing Django projects.
98
+ - **Extensible and Modular**: Build with the same `django.contrib.admin` API, allowing for easy customization and integration with existing Django projects.
101
99
 
102
100
  The project is continuously evolving, with new features and improvements being added regularly. Contributions from the community are highly encouraged to help expand and enhance the capabilities of this tool.
103
101
 
@@ -115,6 +113,8 @@ This section should list any major frameworks/libraries used to bootstrap your p
115
113
 
116
114
  * [![Django][Django]][Django-url]
117
115
  * [![DRF][Django REST framework]][DRF-url]
116
+ * [![DRFSPD][DRF Spectacular]][DRFSPD-url]
117
+
118
118
 
119
119
  <p align="right">(<a href="#readme-top">back to top</a>)</p>
120
120
 
@@ -129,13 +129,9 @@ To set up the project locally, follow these steps:
129
129
 
130
130
  Before you begin, ensure you have met the following requirements:
131
131
 
132
- - **Python 3.8+**: Make sure Python is installed on your machine. You can download it from [python.org](https://www.python.org/downloads/).
133
-
134
- - **pip**: Ensure you have pip installed for managing Python packages. It usually comes with Python installations.
132
+ - **Python 3.12+**: Make sure Python is installed on your machine. You can download it from [python.org](https://www.python.org/downloads/).
135
133
 
136
- - **Virtual Environment**: It's recommended to use a virtual environment to manage dependencies. You can create one using `venv` or `virtualenv`.
137
-
138
- - **rest_framework**
134
+ - **Django REST framework**
139
135
  ```sh
140
136
  pip install djangorestframework
141
137
  ```
@@ -143,18 +139,11 @@ Before you begin, ensure you have met the following requirements:
143
139
  ```sh
144
140
  pip install drf-spectacular
145
141
  ```
146
- - **djangorestframework-simplejwt**
147
- ```sh
148
- pip install djangorestframework-simplejwt
149
- ```
150
- - **django-cors-headers**
151
- ```sh
152
- pip install django-cors-headers
153
- ```
142
+
154
143
 
155
144
  ### Installation
156
145
 
157
- This guide will walk you through the steps to integrate `django-api-admin` into your Django project. Follow these instructions to get started.
146
+ This section will walk you through the steps to install `django-api-admin` in your Django project. Follow these instructions to get started.
158
147
 
159
148
  1. **Install the Package**
160
149
  ```sh
@@ -177,16 +166,7 @@ This guide will walk you through the steps to integrate `django-api-admin` into
177
166
  'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
178
167
  }
179
168
  ```
180
- 4. Add the urls of your client side applications to the `CORS_ORIGIN_WHITELIST`
181
- ```py
182
- # settings.py
183
- CORS_ORIGIN_WHITELIST = (
184
- 'http://localhost', # jest-dom test server
185
- 'http://localhost:3000', # react developement server
186
- )
187
- CORS_ALLOW_CREDENTIALS = True
188
- ```
189
- 5. **Add the modify_schema hook** used to tag paths in the openapi schema
169
+ 4. **Add the modify_schema hook** to improve the auto generated openAPI schema
190
170
  ```py
191
171
  # settings.py
192
172
  SPECTACULAR_SETTINGS = {
@@ -199,6 +179,96 @@ This guide will walk you through the steps to integrate `django-api-admin` into
199
179
 
200
180
  Thats it you are now ready to register your models and implement your django admin frontend!
201
181
 
182
+ ### CORS Configuration
183
+
184
+ If you plan to build a custom frontend in React.js or Vue.js then you might want to consider adding CORS configuration to your Django project. This will allow your frontend to make requests to your Django backend.
185
+
186
+ 1. Install **django-cors-headers** package
187
+ ```sh
188
+ pip install django-cors-headers
189
+ ```
190
+
191
+ 2. Add `corsheaders` to `INSTALLED_APPS` in your Django project's settings.py file (the order doesn't matter):
192
+ ```py
193
+ # settings.py
194
+ INSTALLED_APPS = [
195
+ 'corsheaders',
196
+ # ...
197
+ ]
198
+ ```
199
+
200
+ 3. Add the urls of your client side applications to the `CORS_ORIGIN_WHITELIST`
201
+ ```py
202
+ # settings.py
203
+ CORS_ORIGIN_WHITELIST = (
204
+ 'http://localhost', # jest-dom test server
205
+ 'http://localhost:3000', # react development server
206
+ )
207
+ CORS_ALLOW_CREDENTIALS = True
208
+ ```
209
+
210
+ Your client side application should now be able to make requests to your django backend!
211
+
212
+ ### Authentication
213
+
214
+ Unlike `django.contrib.admin` this package doesn't include it's own authentication functionality. You will need implement authentication on your own, however the `django-api-admin` makes it very easy to add support for authentication frameworks that support `rest_framework`. This is how you can add `django-allauth` for instance:
215
+
216
+ 1. Install `django-allauth`
217
+
218
+ ```sh
219
+ pip install django-allauth
220
+ ```
221
+
222
+ 2. Configure `django-allauth` settings for your project
223
+
224
+ ```py
225
+ # settings.py
226
+
227
+ INSTALLED_APPS = [
228
+ # ...
229
+ 'allauth',
230
+ ]
231
+
232
+ MIDDLEWARE = [
233
+ # ...
234
+ 'allauth.account.middleware.AccountMiddleware',
235
+ # ...
236
+ ]
237
+
238
+ AUTHENTICATION_BACKENDS = [
239
+ 'django.contrib.auth.backends.ModelBackend',
240
+ 'allauth.account.auth_backends.AuthenticationBackend',
241
+ ]
242
+ ```
243
+
244
+ 3. Add the `authentication_classes` to an `APIAdminSite` subclass.
245
+
246
+ ```py
247
+ from django_api_admin import APIAdminSite
248
+
249
+ class AdminSite(APIAdminSite):
250
+ def get_authentication_classes(self):
251
+ from allauth.headless.contrib.rest_framework.authentication import XSessionTokenAuthentication
252
+
253
+ return [XSessionTokenAuthentication, authentication.SessionAuthentication]
254
+
255
+ site = AdminSite()
256
+ ```
257
+
258
+
259
+ 4. include the `django-allauth` headless urls in your `urls.py` file.
260
+
261
+ ```python
262
+ # urls.py
263
+ urlpatterns = [
264
+ # ...
265
+ path("_allauth/", include("allauth.headless.urls")),
266
+ ]
267
+ ```
268
+
269
+ Now, `django-api-admin` will use the provided `authentication_classes` for authenticating users.
270
+
271
+
202
272
  <p align="right">(<a href="#readme-top">back to top</a>)</p>
203
273
 
204
274
 
@@ -262,11 +332,8 @@ This section provides a simple example on how to use django-api-admin. If you're
262
332
  - [x] Rewrite django.contrib.admin as an API
263
333
  - [x] Add support for Bulk Actions
264
334
  - [x] Add OpenAPI documentation
265
- - [ ] Add a customizable dashboard
266
- - [ ] Oauth support
267
- - [ ] Multi-language Support
268
- - [ ] Arabic
269
- - [x] English
335
+ - [ ] Add support for charts
336
+ - [ ] Add support for global full-text search
270
337
 
271
338
  See the [open issues](https://github.com/demon-bixia/django-api-admin/issues) for a full list of proposed features (and known issues).
272
339
 
@@ -310,9 +377,9 @@ Distributed under the MIT License. See the `LICENSE` file for more information.
310
377
  <!-- CONTACT -->
311
378
  ## Contact
312
379
 
313
- Muhammad Salah - [@demobixia](https://t.me/demonbixia) - msbizzaccount@outlook.com
380
+ Muhammad Salah - [@daemobixia](https://t.me/demonbixia) - [msbizzaccount@gmail.com](mailto:[EMAIL_ADDRESS])
314
381
 
315
- Project Link: [https://github.com/demon-bixia/django-api-admin](https://github.com/demon-bixia/django-api-admin)
382
+ Project Link: [https://github.com/demon-bixia/django-api-admin](https://github.com/daemon-bixia/django-api-admin)
316
383
 
317
384
  <p align="right">(<a href="#readme-top">back to top</a>)</p>
318
385
 
@@ -325,10 +392,7 @@ This section is dedicated to recognizing the valuable resources and contribution
325
392
 
326
393
  * [Django Web Framework](https://www.djangoproject.com/)
327
394
  * [Django Rest Framework](https://www.django-rest-framework.org/)
328
- * [Simple JWT](https://github.com/jazzband/djangorestframework-simplejwt/tree/master)
329
- * [Django Cors Headers](https://github.com/adamchainz/django-cors-headers)
330
395
  * [DRF Spectacular](https://github.com/tfranzel/drf-spectacular)
331
- * [Django Restful Admin](https://github.com/amirasaran/django-restful-admin)
332
396
  * [Best README Template](https://github.com/othneildrew/Best-README-Template)
333
397
 
334
398
  <p align="right">(<a href="#readme-top">back to top</a>)</p>
@@ -361,4 +425,7 @@ This section is dedicated to recognizing the valuable resources and contribution
361
425
  [DRF-url]: https://www.django-rest-framework.org/
362
426
  [Django REST framework]: https://img.shields.io/badge/django--rest--framework-3.12.4-green?style=for-the-badge&labelColor=333333&logo=django&logoColor=white&color=green
363
427
 
428
+ [DRFSPD-url]: https://drf-spectacular.readthedocs.io/en/latest/
429
+ [DRF Spectacular]: https://img.shields.io/badge/drf-spectacular-orange?style=for-the-badge&labelColor=333333&logo=django&logoColor=white&color=green
430
+
364
431
  [product-screenshot]: assets/images/screenshot.png
@@ -19,7 +19,7 @@
19
19
  <img src="assets/images/logo.png" alt="Logo" width="300" height="300">
20
20
  </a>
21
21
 
22
- <h3 align="center">Django API Admin</h3>
22
+ <h1 align="center">Django API Admin</h1>
23
23
 
24
24
  <p align="center">
25
25
  A RESTful API implementation of django.contrib.admin, designed for writing custom frontends.
@@ -52,6 +52,8 @@
52
52
  <ul>
53
53
  <li><a href="#prerequisites">Prerequisites</a></li>
54
54
  <li><a href="#installation">Installation</a></li>
55
+ <li><a href="#cors">CORS Configuration</a></li>
56
+ <li><a href="#authentication">Authentication</a></li>
55
57
  </ul>
56
58
  </li>
57
59
  <li><a href="#usage">Usage</a></li>
@@ -70,12 +72,12 @@
70
72
 
71
73
  [![Product Name Screen Shot][product-screenshot]](https://github.com/demon-bixia/django-api-admin)
72
74
 
73
- The Django API Admin project is a RESTful API implementation of the `django.contrib.admin` module, designed to facilitate the creation of custom frontends. This project aims to provide developers with a robust and flexible API that mirrors the functionality of Django's built-in admin interface, allowing for seamless integration with modern web applications.
75
+ Django API Admin is a RESTful API implementation of the `django.contrib.admin` application, designed to make it easy to create custom frontends. This project aims to provide developers with a flexible API that mirrors the functionality of Django's built-in admin interface, allowing for seamless integration with modern web client interfaces.
74
76
 
75
77
  ### Key Features:
76
78
  - **RESTful API**: Offers a comprehensive API for managing Django models, enabling developers to build custom administrative interfaces.
77
79
  - **Custom Frontends**: Designed to support the development of tailored frontends that meet specific project requirements.
78
- - **Extensible and Modular**: Build with the same django.contrib.admin API, allowing for easy customization and integration with existing Django projects.
80
+ - **Extensible and Modular**: Build with the same `django.contrib.admin` API, allowing for easy customization and integration with existing Django projects.
79
81
 
80
82
  The project is continuously evolving, with new features and improvements being added regularly. Contributions from the community are highly encouraged to help expand and enhance the capabilities of this tool.
81
83
 
@@ -93,6 +95,8 @@ This section should list any major frameworks/libraries used to bootstrap your p
93
95
 
94
96
  * [![Django][Django]][Django-url]
95
97
  * [![DRF][Django REST framework]][DRF-url]
98
+ * [![DRFSPD][DRF Spectacular]][DRFSPD-url]
99
+
96
100
 
97
101
  <p align="right">(<a href="#readme-top">back to top</a>)</p>
98
102
 
@@ -107,13 +111,9 @@ To set up the project locally, follow these steps:
107
111
 
108
112
  Before you begin, ensure you have met the following requirements:
109
113
 
110
- - **Python 3.8+**: Make sure Python is installed on your machine. You can download it from [python.org](https://www.python.org/downloads/).
111
-
112
- - **pip**: Ensure you have pip installed for managing Python packages. It usually comes with Python installations.
114
+ - **Python 3.12+**: Make sure Python is installed on your machine. You can download it from [python.org](https://www.python.org/downloads/).
113
115
 
114
- - **Virtual Environment**: It's recommended to use a virtual environment to manage dependencies. You can create one using `venv` or `virtualenv`.
115
-
116
- - **rest_framework**
116
+ - **Django REST framework**
117
117
  ```sh
118
118
  pip install djangorestframework
119
119
  ```
@@ -121,18 +121,11 @@ Before you begin, ensure you have met the following requirements:
121
121
  ```sh
122
122
  pip install drf-spectacular
123
123
  ```
124
- - **djangorestframework-simplejwt**
125
- ```sh
126
- pip install djangorestframework-simplejwt
127
- ```
128
- - **django-cors-headers**
129
- ```sh
130
- pip install django-cors-headers
131
- ```
124
+
132
125
 
133
126
  ### Installation
134
127
 
135
- This guide will walk you through the steps to integrate `django-api-admin` into your Django project. Follow these instructions to get started.
128
+ This section will walk you through the steps to install `django-api-admin` in your Django project. Follow these instructions to get started.
136
129
 
137
130
  1. **Install the Package**
138
131
  ```sh
@@ -155,16 +148,7 @@ This guide will walk you through the steps to integrate `django-api-admin` into
155
148
  'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
156
149
  }
157
150
  ```
158
- 4. Add the urls of your client side applications to the `CORS_ORIGIN_WHITELIST`
159
- ```py
160
- # settings.py
161
- CORS_ORIGIN_WHITELIST = (
162
- 'http://localhost', # jest-dom test server
163
- 'http://localhost:3000', # react developement server
164
- )
165
- CORS_ALLOW_CREDENTIALS = True
166
- ```
167
- 5. **Add the modify_schema hook** used to tag paths in the openapi schema
151
+ 4. **Add the modify_schema hook** to improve the auto generated openAPI schema
168
152
  ```py
169
153
  # settings.py
170
154
  SPECTACULAR_SETTINGS = {
@@ -177,6 +161,96 @@ This guide will walk you through the steps to integrate `django-api-admin` into
177
161
 
178
162
  Thats it you are now ready to register your models and implement your django admin frontend!
179
163
 
164
+ ### CORS Configuration
165
+
166
+ If you plan to build a custom frontend in React.js or Vue.js then you might want to consider adding CORS configuration to your Django project. This will allow your frontend to make requests to your Django backend.
167
+
168
+ 1. Install **django-cors-headers** package
169
+ ```sh
170
+ pip install django-cors-headers
171
+ ```
172
+
173
+ 2. Add `corsheaders` to `INSTALLED_APPS` in your Django project's settings.py file (the order doesn't matter):
174
+ ```py
175
+ # settings.py
176
+ INSTALLED_APPS = [
177
+ 'corsheaders',
178
+ # ...
179
+ ]
180
+ ```
181
+
182
+ 3. Add the urls of your client side applications to the `CORS_ORIGIN_WHITELIST`
183
+ ```py
184
+ # settings.py
185
+ CORS_ORIGIN_WHITELIST = (
186
+ 'http://localhost', # jest-dom test server
187
+ 'http://localhost:3000', # react development server
188
+ )
189
+ CORS_ALLOW_CREDENTIALS = True
190
+ ```
191
+
192
+ Your client side application should now be able to make requests to your django backend!
193
+
194
+ ### Authentication
195
+
196
+ Unlike `django.contrib.admin` this package doesn't include it's own authentication functionality. You will need implement authentication on your own, however the `django-api-admin` makes it very easy to add support for authentication frameworks that support `rest_framework`. This is how you can add `django-allauth` for instance:
197
+
198
+ 1. Install `django-allauth`
199
+
200
+ ```sh
201
+ pip install django-allauth
202
+ ```
203
+
204
+ 2. Configure `django-allauth` settings for your project
205
+
206
+ ```py
207
+ # settings.py
208
+
209
+ INSTALLED_APPS = [
210
+ # ...
211
+ 'allauth',
212
+ ]
213
+
214
+ MIDDLEWARE = [
215
+ # ...
216
+ 'allauth.account.middleware.AccountMiddleware',
217
+ # ...
218
+ ]
219
+
220
+ AUTHENTICATION_BACKENDS = [
221
+ 'django.contrib.auth.backends.ModelBackend',
222
+ 'allauth.account.auth_backends.AuthenticationBackend',
223
+ ]
224
+ ```
225
+
226
+ 3. Add the `authentication_classes` to an `APIAdminSite` subclass.
227
+
228
+ ```py
229
+ from django_api_admin import APIAdminSite
230
+
231
+ class AdminSite(APIAdminSite):
232
+ def get_authentication_classes(self):
233
+ from allauth.headless.contrib.rest_framework.authentication import XSessionTokenAuthentication
234
+
235
+ return [XSessionTokenAuthentication, authentication.SessionAuthentication]
236
+
237
+ site = AdminSite()
238
+ ```
239
+
240
+
241
+ 4. include the `django-allauth` headless urls in your `urls.py` file.
242
+
243
+ ```python
244
+ # urls.py
245
+ urlpatterns = [
246
+ # ...
247
+ path("_allauth/", include("allauth.headless.urls")),
248
+ ]
249
+ ```
250
+
251
+ Now, `django-api-admin` will use the provided `authentication_classes` for authenticating users.
252
+
253
+
180
254
  <p align="right">(<a href="#readme-top">back to top</a>)</p>
181
255
 
182
256
 
@@ -240,11 +314,8 @@ This section provides a simple example on how to use django-api-admin. If you're
240
314
  - [x] Rewrite django.contrib.admin as an API
241
315
  - [x] Add support for Bulk Actions
242
316
  - [x] Add OpenAPI documentation
243
- - [ ] Add a customizable dashboard
244
- - [ ] Oauth support
245
- - [ ] Multi-language Support
246
- - [ ] Arabic
247
- - [x] English
317
+ - [ ] Add support for charts
318
+ - [ ] Add support for global full-text search
248
319
 
249
320
  See the [open issues](https://github.com/demon-bixia/django-api-admin/issues) for a full list of proposed features (and known issues).
250
321
 
@@ -288,9 +359,9 @@ Distributed under the MIT License. See the `LICENSE` file for more information.
288
359
  <!-- CONTACT -->
289
360
  ## Contact
290
361
 
291
- Muhammad Salah - [@demobixia](https://t.me/demonbixia) - msbizzaccount@outlook.com
362
+ Muhammad Salah - [@daemobixia](https://t.me/demonbixia) - [msbizzaccount@gmail.com](mailto:[EMAIL_ADDRESS])
292
363
 
293
- Project Link: [https://github.com/demon-bixia/django-api-admin](https://github.com/demon-bixia/django-api-admin)
364
+ Project Link: [https://github.com/demon-bixia/django-api-admin](https://github.com/daemon-bixia/django-api-admin)
294
365
 
295
366
  <p align="right">(<a href="#readme-top">back to top</a>)</p>
296
367
 
@@ -303,10 +374,7 @@ This section is dedicated to recognizing the valuable resources and contribution
303
374
 
304
375
  * [Django Web Framework](https://www.djangoproject.com/)
305
376
  * [Django Rest Framework](https://www.django-rest-framework.org/)
306
- * [Simple JWT](https://github.com/jazzband/djangorestframework-simplejwt/tree/master)
307
- * [Django Cors Headers](https://github.com/adamchainz/django-cors-headers)
308
377
  * [DRF Spectacular](https://github.com/tfranzel/drf-spectacular)
309
- * [Django Restful Admin](https://github.com/amirasaran/django-restful-admin)
310
378
  * [Best README Template](https://github.com/othneildrew/Best-README-Template)
311
379
 
312
380
  <p align="right">(<a href="#readme-top">back to top</a>)</p>
@@ -339,4 +407,7 @@ This section is dedicated to recognizing the valuable resources and contribution
339
407
  [DRF-url]: https://www.django-rest-framework.org/
340
408
  [Django REST framework]: https://img.shields.io/badge/django--rest--framework-3.12.4-green?style=for-the-badge&labelColor=333333&logo=django&logoColor=white&color=green
341
409
 
410
+ [DRFSPD-url]: https://drf-spectacular.readthedocs.io/en/latest/
411
+ [DRF Spectacular]: https://img.shields.io/badge/drf-spectacular-orange?style=for-the-badge&labelColor=333333&logo=django&logoColor=white&color=green
412
+
342
413
  [product-screenshot]: assets/images/screenshot.png
@@ -0,0 +1,22 @@
1
+ ## Introduction
2
+
3
+ **Django API Admin** is a Django package that provides a powerful, RESTful API admin interface for your Django projects.
4
+
5
+ Key highlights include:
6
+ - **A Modern Rewrite:** It is a complete rewrite of the standard `django.contrib.admin` package, built on top of the **Django Rest Framework (DRF)**.
7
+ - **Frontend-First:** Specifically designed for developers building custom administrative front-ends using modern frameworks like **React**, **Vue**, and **Next.js**.
8
+ - **Full Feature Parity:** It provides a RESTful interface to all default `django.contrib.admin` features out of the box.
9
+ - **Extensible:** Easily customizable to add unique functionality tailored to your specific administrative needs.
10
+
11
+ ## Scope
12
+
13
+ - **Core Support:** It natively supports the full suite of features found in the standard `django.contrib.admin` package.
14
+ - **Unopinionated Auth:** To remain flexible, it does **not** include or enforce any default authentication method.
15
+ - **Beyond a Mirror:** While it follows the patterns of the original admin, it is not strictly a mirror and may include enhanced features or different architectural choices that go beyond the standard Django admin.
16
+
17
+ ## Authentication
18
+
19
+ Authentication is decoupled from the core package to give developers full control over their security stack.
20
+
21
+ - **Developer Responsibility:** Implementation of authentication is left entirely to the developer within their specific project.
22
+ - **Recommendation:** We highly recommend using [Django Allauth Headless](https://django-allauth.readthedocs.io/en/latest/headless.html) for a seamless, modern authentication experience that pairs perfectly with this package.
@@ -1,5 +1,16 @@
1
- from django.utils.module_loading import autodiscover_modules
1
+ # -----------------------------------------------------------------------------
2
+ # Portions of this file are from Django (https://www.djangoproject.com/)
3
+ # Copyright (c) Django Software Foundation and individual contributors.
4
+ # All rights reserved.
5
+ # Licensed under the BSD 3-Clause License.
6
+ #
7
+ # Additional code copyright (c) 2021 Muhammad Salah
8
+ # Licensed under the MIT License
9
+ #
10
+ # This file includes both Django code and your my own contributions.
11
+ # -----------------------------------------------------------------------------
2
12
 
13
+ from django_api_admin.utils.module_loading import autodiscover_modules
3
14
  from django_api_admin.decorators import action, display, register
4
15
  from django_api_admin.filters import (
5
16
  AllValuesFieldListFilter,
@@ -13,8 +24,7 @@ from django_api_admin.filters import (
13
24
  RelatedOnlyFieldListFilter,
14
25
  SimpleListFilter,
15
26
  )
16
- from django_api_admin.constants.vars import HORIZONTAL, VERTICAL
17
- from django_api_admin.admins.model_admin import APIModelAdmin
27
+ from django_api_admin.admins.model_admin import APIModelAdmin, HORIZONTAL, VERTICAL
18
28
  from django_api_admin.admins.inline_admin import StackedInlineAPI, TabularInlineAPI
19
29
  from django_api_admin.sites import APIAdminSite, site
20
30
 
@@ -9,19 +9,15 @@ from django_api_admin.utils.get_deleted_objects import get_deleted_objects
9
9
  from django_api_admin.decorators import action
10
10
 
11
11
 
12
- @action(
13
- permissions=['delete'],
14
- description=gettext_lazy('Delete selected %(verbose_name_plural)s')
15
- )
12
+ @action(permissions=["delete"], description=gettext_lazy("Delete selected %(verbose_name_plural)s"))
16
13
  def delete_selected(modeladmin, request, queryset):
17
14
  """
18
15
  default api_admin action deletes the selected objects
19
16
  no confirmation page
20
17
  """
21
- _deletable_objects, _model_count, perms_needed, _protected = get_deleted_objects(
22
- queryset, request, modeladmin.admin_site)
18
+ _deletable_objects, _model_count, perms_needed, _protected = get_deleted_objects(queryset, request, modeladmin.admin_site)
23
19
 
24
- # check the permissions
20
+ # Check the permissions
25
21
  if perms_needed:
26
22
  objects_name = model_ngettext(queryset)
27
23
  msg = _("Cannot delete %(name)s") % {"name": objects_name}
@@ -30,11 +26,9 @@ def delete_selected(modeladmin, request, queryset):
30
26
  # log the deletion of all the objects inside the queryset
31
27
  n = queryset.count()
32
28
  if n:
33
- for obj in queryset:
34
- modeladmin.log_deletion(request, obj, str(obj))
29
+ modeladmin.log_deletion(request, queryset)
35
30
 
36
- # delete the queryset
37
- queryset.delete()
38
- msg = _("Successfully deleted %s %s.") % (
39
- n, model_ngettext(modeladmin.opts, n))
40
- return Response({'detail': msg}, status=status.HTTP_200_OK)
31
+ # Delete the queryset
32
+ modeladmin.delete_queryset(request, queryset)
33
+ msg = _("Successfully deleted %s %s.") % (n, model_ngettext(modeladmin.opts, n))
34
+ return Response({"detail": msg}, status=status.HTTP_200_OK)
@@ -3,10 +3,9 @@ from django.utils.translation import gettext_lazy as _
3
3
  from rest_framework.response import Response
4
4
  from rest_framework import status
5
5
  from rest_framework.exceptions import ParseError
6
-
7
6
  from rest_framework.views import APIView
8
7
 
9
- from drf_spectacular.utils import extend_schema, OpenApiResponse
8
+ from drf_spectacular.utils import extend_schema, OpenApiResponse, OpenApiParameter
10
9
 
11
10
  from django_api_admin.serializers import AppIndexSerializer, AppSerializer
12
11
  from django_api_admin.openapi import CommonAPIResponses
@@ -14,24 +13,28 @@ from django_api_admin.openapi import CommonAPIResponses
14
13
 
15
14
  class AppIndexView(APIView):
16
15
  """
17
- Lists models inside a given app.
16
+ Retrieve an app that has models registered in the admin site using `app_label`.
18
17
  """
18
+
19
19
  serializer_class = AppIndexSerializer
20
20
  permission_classes = []
21
21
  admin_site = None
22
22
 
23
23
  @extend_schema(
24
- operation_id="app_index",
25
- request=AppIndexSerializer,
26
- responses={
27
- 200: OpenApiResponse(
28
- response=AppSerializer,
29
- description=_(
30
- "Successfully constructed the list of registered models")
24
+ operation_id="Get registered app details",
25
+ parameters=[
26
+ OpenApiParameter(
27
+ name="app_label",
28
+ type=str,
29
+ location=OpenApiParameter.PATH,
30
+ description=_("The label of the app to retrieve details for."),
31
31
  ),
32
+ ],
33
+ responses={
34
+ 200: OpenApiResponse(response=AppSerializer, description=_("Application detail for the given `app_label`")),
32
35
  403: CommonAPIResponses.permission_denied(),
33
- 401: CommonAPIResponses.unauthorized()
34
- }
36
+ 401: CommonAPIResponses.unauthorized(),
37
+ },
35
38
  )
36
39
  def get(self, request, app_label):
37
40
  serializer = self.get_serializer(app_label)
@@ -41,23 +44,17 @@ class AppIndexView(APIView):
41
44
  app_dict = self.admin_site._build_app_dict(request, app_label)
42
45
 
43
46
  if not app_dict:
44
- return Response({'detail': _('The requested admin page does not exist.')},
45
- status=status.HTTP_404_NOT_FOUND)
47
+ return Response({"detail": _("The requested admin page does not exist.")}, status=status.HTTP_404_NOT_FOUND)
46
48
 
47
49
  # Sort the models alphabetically within each app.
48
- app_dict['models'].sort(key=lambda x: x['name'])
50
+ app_dict["models"].sort(key=lambda x: x["name"])
49
51
 
50
52
  data = {
51
- 'app_label': app_label,
52
- 'app': app_dict,
53
+ "app_label": app_label,
54
+ "app": app_dict,
53
55
  }
54
56
  return Response(data, status=status.HTTP_200_OK)
55
57
 
56
58
  def get_serializer(self, app_label):
57
- registered_app_labels = {
58
- model._meta.app_label for model in self.admin_site._registry.keys()
59
- }
60
- return AppIndexSerializer(
61
- data={"app_label": app_label},
62
- context={'registered_app_labels': registered_app_labels}
63
- )
59
+ registered_app_labels = {model._meta.app_label for model in self.admin_site._registry.keys()}
60
+ return self.serializer_class(data={"app_label": app_label}, context={"registered_app_labels": registered_app_labels})