Tested on Django 2.0+
If you want to see all the permissions that the logged in user has, in your template (.html) output:
{{ perms.app_name }}
Or
{{ perms }}
To check if a user has permission, use:
{% if perms.app_name.change_model_name_lower_cased %}
For example:
{% if perms.Utilization.change_invoice %}
Here: Use is the name of my application. Invoice is the name of the model.
Please note that in general there will be 4 types of permissions:
- edit [For example, Utilization.change_projectemail]
- view [For example, Utilization.view_invoice]
- delete [eg Utilization.delete_invoicetype]
- add [For example, Utilization.add_invoicetype]
Also, if you want to see all the permissions that the user has because of the groups to which he belongs, run the Django shell ...
user = User.objects.get(username='somename') user.get_group_permissions()
Here, all of the listed permissions belong to the groups to which it belongs.
Arindam Roychowdhury May 24 '19 at 11:39 a.m. 2019-05-24 11:39
source share