Skip to content

Commit 22b4104

Browse files
author
Cuong Nguyen
authored
Update README.rst
1 parent 8eb81cf commit 22b4104

File tree

1 file changed

+2
-183
lines changed

1 file changed

+2
-183
lines changed

README.rst

Lines changed: 2 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -19,188 +19,7 @@ Enhance UI/UX of django admin
1919
- And more utils functions
2020

2121

22-
Install
22+
Quickstart
2323
=======
2424

25-
.. code:: shell
26-
27-
pip install git+https://github.com/cuongnb14/django-admin-extended.git@v5.0.1#egg=django-admin-extended
28-
29-
Setting
30-
=======
31-
32-
.. code:: python
33-
34-
# Install app, install before django.contrib.admin
35-
INSTALLED_APPS = [
36-
'fontawesomefree',
37-
'admin_extended',
38-
'django.contrib.admin',
39-
...
40-
]
41-
42-
ADMIN_EXTENDED = {
43-
'MENU_APP_ORDER': ['user', 'auth'],
44-
'MENU_MODEL_ORDER': ['User', 'Group'],
45-
'APP_ICON': {
46-
'user': 'fas fa-user',
47-
'auth': 'fas fa-users',
48-
},
49-
'MODEL_ADMIN_TABBED_INLINE': True,
50-
'RAW_ID_FIELDS_AS_DEFAULT': False,
51-
}
52-
53-
- MENU_APP_ORDER: change order of app at left sidebar
54-
- MENU_MODEL_ORDER: change order of model at left sidebar
55-
- APP_ICON: custom icon of menu app use fontawesome v5 (https://fontawesome.com/v5.15/icons?d=gallery&p=2&m=free)
56-
- MODEL_ADMIN_TABBED_INLINE: use tab for model inline. Default is True
57-
- RAW_ID_FIELDS_AS_DEFAULT: use raw_id_fields (or autocomplete_fields if related model have search_fields) as default for related fields instead of select box
58-
59-
60-
61-
Basic Usage
62-
===========
63-
64-
.. code:: python
65-
66-
from django.apps import apps
67-
from django.contrib import admin
68-
from admin_extended.base import ExtendedAdminModel
69-
from . import models
70-
71-
72-
73-
class PostCommentInline(admin.TabularInline):
74-
model = models.PostComment
75-
extra = 0
76-
77-
class PostTagInline(admin.TabularInline):
78-
model = models.PostTag
79-
extra = 0
80-
81-
@admin.register(models.Post)
82-
class PostAdmin(ExtendedAdminModel):
83-
list_display = ('id', 'title', 'post_at')
84-
search_fields = ('title',)
85-
search_help_text = 'Search by title'
86-
list_filter = ('status',)
87-
inlines = [
88-
PostCommentInline,
89-
PostTagInline
90-
]
91-
92-
**ExtendedAdminModel options**
93-
94-
- **raw_id_fields_as_default** (boolean, default True) Use raw_id_fields (or autocomplete_fields if related model have search_fields) as default for ForeginKey instead of select box (optimize performance for large database)
95-
- **delete_without_confirm** (boolean, default False) Ignore confirm page for delete action
96-
- **tab_inline** (boolean, default from setting) Use tab for model inline (override value in setting)
97-
- **super_admin_only_fields** (list, default []) Only show these fields if user login is superuser
98-
- **ext_read_only_fields** (list, default []) Only show these fields in view mode. Default custom fields start with `display_` was mark as read only so you don't need add these fields to ext_read_only_fields
99-
- **ext_write_only_fields** (list, default []) Only show these fields in edit mode
100-
- **enable_foreign_link** (boolean, default True) Add link for foregin key in change list page
101-
102-
103-
Advand
104-
======
105-
Add custom object tools item in change list or change form
106-
----------------------------------------------------------
107-
108-
.. code:: python
109-
110-
from admin_extended.decorators import object_tool
111-
from admin_extended.base import ExtendedAdminModel
112-
113-
@admin.register(models.Customer)
114-
class CustomerAdmin(ExtendedAdminModel):
115-
change_form_object_tools = ['demo_change_form_action']
116-
change_list_object_tools = ['demo_change_list_action']
117-
118-
@object_tool(icon='fas fa-edit', name='do_something', description='Do something', http_method='post', post_param_title='Name')
119-
def demo_change_form_action(self, request, object_id):
120-
customer = models.Customer.objects.get(pk=object_id)
121-
context = {
122-
**admin.site.each_context(request),
123-
'title': f'Update customer {customer.name}',
124-
}
125-
if request.method == 'POST':
126-
form = CustomForm(request.POST)
127-
messages.success(request, request.POST.get('data'))
128-
if form.is_valid():
129-
print(form.cleaned_data)
130-
return redirect(reverse('admin:shop_customer_change', args=[object_id]))
131-
context["form"] = CustomForm()
132-
return render(request, 'admin/custom/custom_form.html', context)
133-
134-
@object_tool(icon='fas fa-edit', name='demo_change_list_action', description='Do something')
135-
def demo_change_list_action(self, request):
136-
context = {
137-
**admin.site.each_context(request),
138-
'title': f'Import customer',
139-
}
140-
if request.method == 'POST':
141-
form = CustomForm(request.POST)
142-
if form.is_valid():
143-
print(form.cleaned_data)
144-
return redirect(reverse('admin:shop_customer_changelist'))
145-
context["form"] = CustomForm()
146-
return render(request, 'admin/custom/custom_form.html', context)
147-
148-
**Result**
149-
150-
- Change list object tool
151-
152-
.. image:: screenshots/demo-change-list-object-tools.png?raw=true
153-
154-
- Change form object tool
155-
156-
.. image:: screenshots/demo-change-form-object-tools.png?raw=true
157-
.. image:: screenshots/demo-custom-object-tools.png?raw=true
158-
159-
160-
**object_tool(function=None, *, icon=None, name=None, description=None, http_method='get', post_param_title=None)**
161-
162-
- icon: icon of button
163-
- name: name of object tool (must unique)
164-
- description: label of button
165-
- http_method: Only affect in change form page. with http_method is post, you can pass one param when submit object tool.
166-
- post_param_title: Only affect when http_method is post. Title of param you want to pass.
167-
168-
Add bookmark
169-
------------
170-
- Go to page you want add to bookmark
171-
- Click bookmark button add bottom right
172-
- Choose name of bookmark
173-
- You also can manage book mark (add, delete, change order, ...) in bookmark model
174-
175-
.. image:: screenshots/demo-bookmark.png?raw=true
176-
177-
Automatically Register All Models In Django Admin
178-
-------------------------------------------------
179-
Add this code at **end of admin.py file** of **lastest install app (INSTALLED_APPS setting)**
180-
181-
.. code:: python
182-
183-
from admin_extended.utils import auto_register_model_admin
184-
185-
auto_register_model_admin()
186-
187-
**auto_register_model_admin(default_model_admin_class=DefaultModelAdmin, ignore_models=[]):**
188-
This function will automatic register admin for all unregistered model
189-
190-
- default_model_admin_class: DefaultModelAdmin will list all fields (exclude TextField) of model in change list page, you can custom your model admin and pass to this param
191-
- ignore_models: list model you don't want auto register. specify by <app_label>.<model_name>. Eg: 'users.user'
192-
193-
194-
Screenshots
195-
===========
196-
- Change list page
197-
198-
.. image:: screenshots/change-list-page.png?raw=true
199-
200-
- Read only mode
201-
202-
.. image:: screenshots/view-mode.png?raw=true
203-
204-
- Edit mode
205-
206-
.. image:: screenshots/edit-mode.png?raw=true
25+
Documentation: https://github.com/cuongnb14/django-admin-extended/wiki

0 commit comments

Comments
 (0)