I want to create a permission (or something that achieves the same thing) that can be applied to all users optionally, including super users.
I can create a custom permission very easily:
ct = ContentType.objects.get_for_model(MyModel)
Permission.objects.create(
name='optional permission',
codename='optional_permission,
content_type=ct)
However, this will always return True for superusers user.has_perm('my_app_label.optional_permission')
My use-case is:
I'd like to create a queryset manager function that only returns Draft articles for users in Groups that have optional_permission applied. I'd like superusers to be exempt from seeing these draft articles if they want.
You could try to override
has_permby passing an additional keyword argument to the original implementation.Take a look of
has_permsource code:AbstractUserinheritshas_permmethod fromPermissionMixin