|
1 | 1 |
|
2 | | -# WOLFx Admin Configuration |
| 2 | +# Welcome to the WOLFx Admin Configuration repository! 🚀 |
| 3 | +WOLFx Admin configuration is created to improve the developer experience by simplifying the process of registering models in the admin site. This powerful tool is designed to automate admin registrations but it does not compromise the features that Django's default admin site provides. You can control the admin interface directly from your `models.py` file using a simple `admin_meta` dictionary. This approach eliminates the need for repetitive tasks associated with traditional model registration and allows for direct control over the admin interface, keeping your configurations closely tied to your model definitions. |
3 | 4 |
|
4 | | -This repository contains the configuration for the WOLFx Admin interface. Below are the instructions and details to understand and extend the functionality of the admin interface. |
5 | | - |
6 | | -## Usage |
| 5 | +## Key Features |
| 6 | +1. **Automated Model Registration: Automatically register your models in the Django admin site without the hassle of manually creating admin classes.** |
| 7 | +2. **Direct Control from Models: Manage your admin configurations right next to your model definitions using the admin_meta dictionary.** |
| 8 | +3. **Maintains Django Admin Features: Retain all the robust features offered by Django's default admin site while enjoying the benefits of simplified management.** |
7 | 9 |
|
| 10 | +## Usage |
8 | 11 | 1. **Place the code in the `admin.py` file of your Django application.** |
9 | 12 | 2. **Adjust the configuration constants as needed.** |
10 | 13 | 3. **Define `admin_meta` in your models to customize the admin interface.** |
11 | 14 |
|
12 | | -## Example Model Configuration 🛠️ |
| 15 | +## NOTE: Configuration Constants 📌 |
| 16 | +- `admin.site.site_header`: Sets the header for the admin site. |
| 17 | +- `exempt`: A list of model names that should not be registered with the admin. Note that the model_name should be used and not model itself, to understand better uncomment the `print(model_name + ' ' + str(model))` in the second last line of the code to see what is the actual model_name of your model |
| 18 | +- `global_app_name`: The name of the application. This constant determines from which app it needs to pull the models for auto-registration. As every app has its admin.py, this constant's value should be the name of its own app. For example if your app name is `web` and the admin.py belongs to this app then the value of this constant should be `web` |
13 | 19 |
|
| 20 | +## Example Model Configuration 🛠️ |
14 | 21 | Here's an example of how you can define your models to leverage the dynamic admin interface: |
15 | 22 |
|
16 | 23 | ```python |
@@ -77,17 +84,15 @@ class BlogImage(CommonModel): |
77 | 84 | ``` |
78 | 85 |
|
79 | 86 | ### Using `admin_meta` Dictionary |
80 | | - |
81 | | -You can control the admin interface directly from your `models.py` using the `admin_meta` dictionary. Here are some key attributes you can define: |
| 87 | +You can control the admin interface directly from your `models.py` using the `admin_meta` dictionary. Here are some key attributes you can define but are not limited to: |
82 | 88 |
|
83 | 89 | - **`list_display`**: Specify fields to be displayed in the list view. |
84 | 90 | - **`list_editable`**: Fields that can be edited directly in the list view. |
85 | 91 | - **`list_filter`**: Fields to filter the list view. |
86 | 92 | - **`inline`**: Define inline models to be displayed. |
87 | 93 |
|
88 | 94 | ### Example with JSONField Schema |
89 | | - |
90 | | -If you have a JSONField in your model, you can customize its form field using a schema: |
| 95 | +If you have a JSONField in your model, you can customize its form field using a schema, note that this makes use of another [open-source project](https://github.com/json-editor/json-editor) and in this version, it's been muted: |
91 | 96 |
|
92 | 97 | ```python |
93 | 98 | class MyModel(models.Model): |
@@ -123,7 +128,6 @@ class MyModel(models.Model): |
123 | 128 | ``` |
124 | 129 |
|
125 | 130 | ### JSON Editor Widget |
126 | | - |
127 | 131 | The `JsonEditorWidget` class is used to render JSON fields with a user-friendly JSON editor: |
128 | 132 |
|
129 | 133 | ```python |
@@ -156,63 +160,15 @@ class JsonEditorWidget(widgets.Widget): |
156 | 160 | ''') |
157 | 161 | ``` |
158 | 162 |
|
159 | | -## Note 📌 |
160 | | - |
161 | | -Make sure to replace `'web'` with your actual app name in the `global_app_name` variable. |
162 | | - |
163 | | -## Configuration Constants |
164 | | - |
165 | | -- `admin.site.site_header`: Sets the header for the admin site. |
166 | | -- `exempt`: A list of model names that should not be registered with the admin. |
167 | | -- `global_app_name`: The name of the application. |
168 | | - |
169 | | -## GenericStackedAdmin Class |
170 | | - |
171 | | -This class is used for inline models in the admin interface. |
172 | | - |
173 | | -### get_formset |
174 | | - |
175 | | -This method ensures the field order is correct for inlines. |
176 | | - |
177 | | -## GenericAdmin Class |
178 | | - |
179 | | -This class provides a dynamic admin interface for models. |
180 | | - |
181 | | -### __init__ |
182 | | - |
183 | | -- Initializes the admin interface for the model. |
184 | | -- Registers inlines and actions dynamically based on model attributes. |
185 | | - |
186 | | -### formfield_for_dbfield |
187 | | - |
188 | | -- Customizes the form field for JSONField using a schema if defined in the model's admin_meta. |
189 | | - |
190 | | -### get_fieldsets |
191 | | - |
192 | | -- Defines fieldsets for the admin interface. |
193 | | -- If fieldsets are defined in admin_meta, those are used. |
194 | | - |
195 | | -### get_readonly_fields |
196 | | - |
197 | | -- Returns a list of non-editable fields. |
198 | | - |
199 | | -### add_action |
200 | | - |
201 | | -- Adds an action to the admin interface. |
202 | | - |
203 | | -### register_inlines |
204 | | - |
205 | | -- Registers inlines for the admin interface. |
206 | | - |
207 | | -### add_inline |
208 | | - |
209 | | -- Adds an inline model to the admin interface. |
| 163 | +## What is WOLFx? |
| 164 | +[WOLFx Digital Agency](https://wolfx.io) is a premier IT development company located in the financial capital of India, Mumbai. We specialize in delivering cutting-edge technology solutions and IT services, catering to businesses across various domains and helping them thrive in a digital landscape. Our services include custom software development, web and mobile application development, IT consulting, IT Outsourcing/Staffing, and Digital transformation. |
210 | 165 |
|
211 | | -## Dynamic App Registrations |
| 166 | +In addition to our commercial endeavors, WOLFx Digital Agency is deeply committed to the open-source community. We actively contribute to open-source projects, sharing our expertise and innovations with the wider tech community. |
212 | 167 |
|
213 | | -The models from the specified application are dynamically registered to the admin interface unless they are in the exempt list or have 'histor' in their name. |
| 168 | +## Contribution |
| 169 | +We welcome contributions to improve and expand the capabilities of WOLFx Admin Configuration. Please feel free to submit issues, feature requests, or pull requests. |
214 | 170 |
|
215 | | -## Media |
| 171 | +## License |
| 172 | +This project is licensed under the MIT License. See the LICENSE file for details. |
216 | 173 |
|
217 | | -Custom media files can be included using the Media class. |
218 | 174 |
|
0 commit comments