Reputation: 355
This is my code in Views.py
class NotificationsViewSet(viewsets.ModelViewSet):
permission_classes = [permissions.IsAuthenticated, TokenHasReadWriteScope]
queryset = Notifications.objects.all()
serializer_class = NotificationsSerializer
filter_fields = ('status','task','survey_type',)
def put(self, request, pk, format=None):
notifications = self.get_object(pk)
serializer = NotificationsSerializer(notifications, data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def delete(self, request, pk, format=None):
notifications = self.get_object(pk)
notifications.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
When i try to use method PUT i got error put() takes at least 3 arguments (2 given)
. What is wrong with my code?
Upvotes: 1
Views: 3098
Reputation: 20976
That's probably because you're doing a PUT on the set entry point where the pk isn't defined. Make it optional:
def put(self, request, pk=None, format=None):
Note that there's no point in using viewset if you're overriding put
.
Upvotes: 0
Reputation: 1342
def put(self, request, pk, format=None):
It takes 3 arguments at the minimum. Like:
self.put(request, pk)
self
variable needs to be passed.
Alternatively,
put(self, request, pk)
Or 4 arguments at the max,
self.put(request, pk, format)
Upvotes: 1