Changes between Initial Version and Version 1 of Ticket #37021
- Timestamp:
- Apr 2, 2026, 12:58:19 PM (3 hours ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #37021 – Description
initial v1 1 2 1 When 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}` 3 2 … … 9 8 My desired outcome is to be able to do the following. 10 9 11 ``` 10 11 12 {{{ 12 13 user_permissions = Permission.objects.filter(...) 13 14 for perm in user_permissions: 14 15 if user.has_perm(perm.perm_string()): 15 16 # let them do stuff 17 }}} 16 18 17 19 18 ```19 20 20 21 Currently I am doing it as follows: 21 22 22 ``` 23 {{{ 23 24 if user.has_perm(f"{perm.content_type.app_label}.{perm.codename}"): 24 25 # let them do stuff 25 ``` 26 }}} 26 27 27 28 Proposal: … … 29 30 To add a function within `Permission` class: 30 31 31 ``` 32 {{{ 32 33 def perm_string(self): # feel free to suggest other name 33 34 return f"{self.content_type.app_label}.{self.codename}" 34 35 35 ``` 36 }}} 36 37 37 38 If you agree, I would like to try to create the PR for this.