I have a tour and a group model. Whenever a new group gets created I would like to adjust the tour size fields. If I understood correctly, the dispatch() method is the right place for this. However I receive following error:
AttributeError at /booking/newgroup/
'WSGIRequest' object has no attribute 'data'
def reduceTourSize(id, pers):
t = Tour.objects.get(id=id)
t.available_size = t.available_size - int(pers)
t.current_size = t.current_size + int(pers)
t.save()
return t.current_size
class NewGroup(generics.CreateAPIView):
serializer_class = GroupListSerializer
queryset = Group.objects.all()
def dispatch(self, request, *args, **kwargs):
myresult = reduceTourSize(request.data['tour'], request.data['persons'])
return Response(data={"current_size": myresult})
So how can I access the parameters passed in via POST?