How to check current user's permissions from a Group in Django? How to check current user's permissions from a Group in Django? django django

How to check current user's permissions from a Group in Django?


Try this:

if request.user.has_perm('app_name.can_add_cost_price'):

From the docs:

where each perm is in the format 'app_label.permission codename'


When you are working with permissions groups you don't need to check for each permission the user has. If the user is part of the permission group you created in the Django admin just change "YourGroupName" to the name your called your group when you created it

        {% ifequal user.groups.all.0.name "YourGroupName" %}          <div>This is User</div>        {% endifequal %}