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.
I had to implement a slightly ugly workaround in the end, so would be interested to know if someone can do better.
I had to add an override boolean for superusers on our User model