2👍
✅
I figured out some less code fix for my issue.
class PostViewSet(viewsets.ModelViewSet):
queryset = Post.objects.all()
serializer_class = PostStatSerializer
def update(self, request, *args, **kwargs):
super().update(request, *args, **kwargs)
instance = self.get_object()
return Response(AuthorSerializer(instance.author).data)
3👍
You can override update
method for this:
class PostViewSet(viewsets.ModelViewSet):
queryset = Post.objects.all()
serializer_class = PostStatSerializer
def update(self, request, *args, **kwargs):
partial = kwargs.pop('partial', False)
instance = self.get_object()
serializer = self.get_serializer(instance, data=request.data, partial=partial)
serializer.is_valid(raise_exception=True)
self.perform_update(serializer)
# this will return autor's data as a response
return Response(AuthorSerializer(instance.parent).data)
- [Django]-Run Django commands on Elastic Beanstalk SSH -> Missing environment variables
- [Django]-Print long integers in python
- [Django]-Django settings.py statement executed twice
- [Django]-Django and Nginx try_files 403 for site root page
- [Django]-ImportError when using virtualenv in Django
Source:stackexchange.com