Y
Y
YuriyCherniy2019-12-21 14:07:02
Django
YuriyCherniy, 2019-12-21 14:07:02

What is the correct way to call the get method of the CreateView parent class in Django?

In the overridden get method, you need to implement an access check and call the parent get() if the check was successful. How to do it right?

class ItemCreateView(CreateView):
    model = Item
    fields = ['title', 'description', 'image', 'price']

    def get(self, request):
        if not request.user.is_staff:
            raise PermissionDenied
        super() #???????????

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
antonksa, 2019-12-21
@YuriyCherniy

def get(self, request, **kwargs):
        if not request.user.is_staff:
            raise PermissionDenied
        super().get(request, **kwargs)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question