When I make a GET request to my /api/posts/ I recieve only author ID, but I also want author username to display it. How would I do that?
I want response to be something like this:
[
{
// all other stuff
author: {
id: 1,
username: "foo"
}
}
]
This is my Post viewset:
class PostViewSet(viewsets.ModelViewSet):
"""Handle CRUD for Posts"""
serializer_class = serializers.PostSerializer
authentication_classes = (TokenAuthentication,)
queryset = Post.objects.all()
def perform_create(self, serializer):
"""Set author to current user"""
serializer.save(user=self.request.user)
And this is what I get in response:
[
{
"id": 1,
"title": "Welcome!",
"description": "Welcome test!",
"created_at": "2019-09-21T01:05:58.170330Z",
"author": 1,
"community": 2
}
]
I want to do the same for community as well but I think I'll figure it out from the author solution.