Skip to content

Commit 88adde3

Browse files
authored
Create README.md
1 parent f1df62a commit 88adde3

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
2+
# WOLFx Admin Configuration
3+
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+
## Configuration Constants
7+
8+
- `admin.site.site_header`: Sets the header for the admin site.
9+
- `exempt`: A list of model names that should not be registered with the admin.
10+
- `global_app_name`: The name of the application.
11+
12+
## GenericStackedAdmin Class
13+
14+
This class is used for inline models in the admin interface.
15+
16+
### get_formset
17+
18+
This method ensures the field order is correct for inlines.
19+
20+
## GenericAdmin Class
21+
22+
This class provides a dynamic admin interface for models.
23+
24+
### __init__
25+
26+
- Initializes the admin interface for the model.
27+
- Registers inlines and actions dynamically based on model attributes.
28+
29+
### formfield_for_dbfield
30+
31+
- Customizes the form field for JSONField using a schema if defined in the model's admin_meta.
32+
33+
### get_fieldsets
34+
35+
- Defines fieldsets for the admin interface.
36+
- If fieldsets are defined in admin_meta, those are used.
37+
38+
### get_readonly_fields
39+
40+
- Returns a list of non-editable fields.
41+
42+
### add_action
43+
44+
- Adds an action to the admin interface.
45+
46+
### register_inlines
47+
48+
- Registers inlines for the admin interface.
49+
50+
### add_inline
51+
52+
- Adds an inline model to the admin interface.
53+
54+
## Dynamic App Registrations
55+
56+
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.
57+
58+
## Media
59+
60+
Custom media files can be included using the Media class.
61+
62+
## Usage
63+
64+
- Place the code in the `admin.py` file of your Django application.
65+
- Adjust the configuration constants as needed.
66+
- Define `admin_meta` in your models to customize the admin interface.
67+
68+
## Example Model Configuration
69+
70+
```python
71+
class MyModel(models.Model):
72+
name = models.CharField(max_length=255)
73+
data = models.JSONField()
74+
75+
admin_meta = {
76+
'json_fields': {
77+
'data': {
78+
'schema': {
79+
'type': 'object',
80+
'properties': {
81+
'key': {'type': 'string'},
82+
'value': {'type': 'number'}
83+
}
84+
}
85+
}
86+
},
87+
'fieldsets': (
88+
(None, {
89+
'fields': ('name', 'data')
90+
}),
91+
),
92+
'actions': ['custom_action'],
93+
'inline': [
94+
{'RelatedModel': 'mymodel'}
95+
]
96+
}
97+
98+
def custom_action(self, request):
99+
# Custom action logic
100+
pass
101+
```
102+
103+
## Note
104+
105+
Make sure to replace `'web'` with your actual app name in the `global_app_name` variable.

0 commit comments

Comments
 (0)