Opened 6 years ago
Closed 6 years ago
#31266 closed New feature (wontfix)
Implement `user.is_member(group)` to easily check whether a user belongs to a group or not
| Reported by: | Martin Zugnoni | Owned by: | Martin Zugnoni |
|---|---|---|---|
| Component: | contrib.auth | Version: | dev |
| Severity: | Normal | Keywords: | auth, groups, users |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
While checking if a user is member of certain group, there's no easy way to check it other than going through the "groups" M2M relationship manually, like this.
> user.groups.filter(name="some-group").exists() True
I propose to extend the django.contrib.auth.models.PermissionsMixin class, with a is_member(group) method, that returns True/False checking whether the user belongs to the group or not. Similar to the user.has_perm("some-permission"), but for groups.
The same operation using this new method would look like this:
> user.is_member("some-group") True
I'm open to suggestions.
Change History (2)
comment:1 by , 6 years ago
| Version: | 3.0 → master |
|---|
comment:2 by , 6 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | assigned → closed |
Hi Martin. I'm going to say this isn't worth the extra API surface area.
(You can canvas the DevelopersMailingList if you wish but...)
Thanks.