Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom control to django admin site?

Hey, I want to add custom buttom to the django admin site, and the users must be administrators, I do not expect you tell me how to do in each step, but please brief write the right approach, if you also can provide some reading URLs, that's gonna be awesome.

like image 926
user469652 Avatar asked Oct 29 '10 04:10

user469652


2 Answers

http://docs.djangoproject.com/en/dev/intro/tutorial02/ - "Customize the admin form" shows how to modify the admin section of an app.

http://docs.djangoproject.com/en/dev/topics/auth/ - "get_group_permissions()" will allow you to get the group permissions of a user. "has_perm()" returns true for a single permission.

http://docs.djangoproject.com/en/dev/howto/custom-management-commands/ - how to customize django management

http://docs.djangoproject.com/en/dev/ref/contrib/admin/ - "ModelAdmin" can be used to specify a template for the admin site

Using these, you can put together a custom template with any custom controls and only show them if the user has a specific permission.

like image 68
Scott Avatar answered Oct 16 '22 11:10

Scott


You can copy from django /django/contrib/admin/templates/admin/base.html (or base_site.html) to your project /templates/admin/base.html then customize base.html

This part {% block footer %}<div id="footer"></div>{% endblock %}

Also this peace of template could help {% if user.is_active and user.is_staff %}

like image 41
mapcuk Avatar answered Oct 16 '22 10:10

mapcuk