name 'request/self' is not defined

Viewed 126

Getting requests is not defined. please find the below code(I'm not using it directly in CBV).

views.py

 class ShiftChangeUpdateView(request,PermissionRequiredMixin,UpdateView):
        permission_required = ('apple.change_shiftchange',)
        model=ShiftChange
        logger.info('Data has been Deleted by  %s !', request.user.username)
        fields='__all__'

I have checked by using self also but no luck. urls.py

   url(r'^updategenesys/(?P<pk>\d+)/$', views.ShiftChangeUpdateView.as_view()),

How to fix this issue?

2 Answers

You are trying to use parameters like in a function, but that is not how a class is defined. You thus can not use request as a base class.

What you can do is override form_valid, and perform logging in that method when the form is successful:

#                  no request ↓
class ShiftChangeUpdateView(PermissionRequiredMixin, UpdateView):
    permission_required = ('apple.change_shiftchange',)
    model=ShiftChange
    fields='__all__'

    def form_valid(self, form):
        logger.info('Data has been Deleted by  %s !', self.request.user.username)
        return super().form_valid(form)

In the class you don’t inherit request

Related