- Notifications
You must be signed in to change notification settings - Fork0
Enhance UI/UX of django admin
License
NotificationsYou must be signed in to change notification settings
santhosh-programmer/django-admin-extended
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Enhance UI/UX of django admin
Features:
- Custom order menu item
- Restyle sidebar menu UI, collapse menu
- Restyle align for form row in change page
- Collapse filter box
- Admin inlines tabbable
- Read only mode
- Bookmark menu
- Ignore confirm delete page option
- Add link for foregin key in change list page
- And more utils functions
pip install git+https://github.com/santhosh-programmer/django-admin-extended.git
# Install app, install before django.contrib.adminINSTALLED_APPS= ['admin_extended','django.contrib.admin', ...]ADMIN_EXTENDED= {'MENU_APP_ORDER': ['user','auth'],'MENU_MODEL_ORDER': ['User','Group'],'MODEL_ADMIN_TABBED_INLINE':True,'RAW_ID_FIELDS_AS_DEFAULT':False,}
- MENU_APP_ORDER: change order of app at left sidebar
- MENU_MODEL_ORDER: change order of model at left sidebar
- MODEL_ADMIN_TABBED_INLINE: use tab for model inline. Default is True
- 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
fromdjango.appsimportappsfromdjango.contribimportadminfromadmin_extended.baseimportExtendedAdminModelfrom .importmodelsclassPostCommentInline(admin.TabularInline):model=models.PostCommentextra=0classPostTagInline(admin.TabularInline):model=models.PostTagextra=0@admin.register(models.Post)classPostAdmin(ExtendedAdminModel):list_display= ('id','title','post_at')search_fields= ('title',)search_help_text='Search by title'list_filter= ('status',)inlines= [PostCommentInline,PostTagInline ]
ExtendedAdminModel options
- 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)
- delete_without_confirm (boolean, default False) Ignore confirm page for delete action
- tab_inline (boolean, default from setting) Use tab for model inline (override value in setting)
- super_admin_only_fields (list, default []) Only show these fields if user login is superuser
- 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
- ext_write_only_fields (list, default []) Only show these fields in edit mode
- enable_foreign_link (boolean, default True) Add link for foregin key in change list page
fromadmin_extended.decoratorsimportobject_toolfromadmin_extended.baseimportExtendedAdminModel@admin.register(models.Customer)classCustomerAdmin(ExtendedAdminModel):change_form_object_tools= ['demo_change_form_action']change_list_object_tools= ['demo_change_list_action']@object_tool(name='do_something',description='Do something',http_method='post',post_param_title='Name')defdemo_change_form_action(self,request,object_id):customer=models.Customer.objects.get(pk=object_id)context= {**admin.site.each_context(request),'title':f'Update customer{customer.name}', }ifrequest.method=='POST':form=CustomForm(request.POST)messages.success(request,request.POST.get('data'))ifform.is_valid():print(form.cleaned_data)returnredirect(reverse('admin:shop_customer_change',args=[object_id]))context["form"]=CustomForm()returnrender(request,'admin/custom/custom_form.html',context)@object_tool(name='demo_change_list_action',description='Do something')defdemo_change_list_action(self,request):context= {**admin.site.each_context(request),'title':f'Import customer', }ifrequest.method=='POST':form=CustomForm(request.POST)ifform.is_valid():print(form.cleaned_data)returnredirect(reverse('admin:shop_customer_changelist'))context["form"]=CustomForm()returnrender(request,'admin/custom/custom_form.html',context)
Result
- Change list object tool
- Change form object tool
object_tool(function=None, *, icon=None, name=None, description=None, http_method='get', post_param_title=None)
- icon: icon of button
- name: name of object tool (must unique)
- description: label of button
- http_method: Only affect in change form page. with http_method is post, you can pass one param when submit object tool.
- post_param_title: Only affect when http_method is post. Title of param you want to pass.
- Go to page you want add to bookmark
- Click bookmark button add bottom right
- Choose name of bookmark
- You also can manage book mark (add, delete, change order, ...) in bookmark model
Add this code atend of admin.py file oflastest install app (INSTALLED_APPS setting)
fromadmin_extended.utilsimportauto_register_model_adminauto_register_model_admin()
auto_register_model_admin(default_model_admin_class=DefaultModelAdmin, ignore_models=[]):This function will automatic register admin for all unregistered model
- 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
- ignore_models: list model you don't want auto register. specify by <app_label>.<model_name>. Eg: 'users.user'
- Change list page
- Read only mode
- Edit mode
About
Enhance UI/UX of django admin
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.






