CreateView django-role-permission

87 Views Asked by At

I use django-role-permission library for use roles and I have CreateView:

class CreatePostView(CreateView):
    model = apps.blog.models.Post
    form_class = PostForm
    template_name = 'cabinet/post/create.html'
    success_url = "/cabinet/post"

And I want this view can access only user with role: edit_posts

1

There are 1 best solutions below

0
Andrew Stetsko On

I only need to extend my class and put need permission:

class CreatePostView(HasPermissionsMixin, CreateView):
    required_permission = 'edit_posts'
    model = apps.blog.models.Post
    form_class = PostForm
    template_name = 'cabinet/post/create.html'
    success_url = "/cabinet/post"