def post(self, request, pk=None):
     data = json.loads(request.body)
     data['owner'] = request.user.pk
     form = TodoForm(data=data)
     if form.is_valid():
         form.save()
         return self.render({'id': form.instance.pk})
     else:
         return self.render(form.errors, error=True)
 def put(self, request, pk):
     todo = get_object_or_404(Todo, pk=pk, owner=request.user)
     data = json.loads(request.body)
     data['owner'] = request.user.pk
     form = TodoForm(data=data, instance=todo)
     if form.is_valid():
         form.save()
         return self.render()
     else:
         return self.render(form.errors, error=True)