0

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

Andrew Stetsko
  • 87
  • 1
  • 1
  • 9

1 Answers1

0

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"
Andrew Stetsko
  • 87
  • 1
  • 1
  • 9