Changes between Initial Version and Version 1 of Ticket #37021


Ignore:
Timestamp:
Apr 2, 2026, 12:58:19 PM (3 hours ago)
Author:
Mariatta
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #37021 – Description

    initial v1  
    1 
    21When checking user's permission using `user.has_perm()`, I need to pass a string in the format of `{Permission.content_type.app_label}.{Permission.codename}`
    32
     
    98My desired outcome is to be able to do the following.
    109
    11 ```
     10
     11
     12{{{
    1213user_permissions = Permission.objects.filter(...)
    1314for perm in user_permissions:
    1415    if user.has_perm(perm.perm_string()):
    1516        # let them do stuff
     17}}}
    1618
    1719
    18 ```
    1920
    2021Currently I am doing it as follows:
    2122
    22 ```
     23{{{
    2324if user.has_perm(f"{perm.content_type.app_label}.{perm.codename}"):
    2425        # let them do stuff
    25 ```
     26}}}
    2627
    2728Proposal:
     
    2930To add a function within `Permission` class:
    3031
    31 ```
     32{{{
    3233def perm_string(self): # feel free to suggest other name
    3334    return f"{self.content_type.app_label}.{self.codename}"
    3435
    35 ```
     36}}}
    3637
    3738If you agree, I would like to try to create the PR for this.
Back to Top