I am trying to implement a web app in django where I have a class based view that inherits from PermissionRequiredMixin
and generics.View
.
Here is an example model:
class SomeModel(models.Model):
# Here I will put some model attributes
class Meta:
permissions = (
('some_permission', 'Can do some job'),
)
Until now I am not confused yet. However, when I am trying to write the view, I am confused. I read some Stack Overflow questions and also the django documentation, but I did not understand well because they are writing something like this:
class MyView(PermissionRequiredMixin, View)
permission_required = ('polls.can_open', 'polls.can_edit')
I tried to figure out what to write in my case, and I ended up in writing this:
class SomeView(PermissionRequiredMixin, View):
permission_denied_message = 'You don\'t have permission'
permission_required = 'app_name.some_permission'
What made me in doubt is that PyCharm did not auto-complete when I wrote the last line which is: permission_required = 'app_name.some_permission'
. Also, I am not sure whether django will know which permission that I am talking about here.
Did I understand how to do the job? or I am wrong? Should I write it like this: permission_required = 'app_name.SomeModel.some_permission'
?