1👍
✅
For everyone trying to get the profile for a user this is the way I managed to do it thanks to Kevin’s help.
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
depth = 1
fields = ('id','username','email','profile')
class CurrentUserView(APIView):
def get(self, request):
serializer = UserSerializer(request.user)
return Response(serializer.data)
Using a url like this
url(r'^api/current-user',CurrentUserView.as_view(),
name="current_user"),
You will get an answer like this
"id": 1,
"username": "username",
"email": "email@email.com",
"profile": {
"id": 1,
"user": 1,
"bio": "My Bio",
"sex": "M",
"birthdate": "1987-12-02"
}
1👍
You didn’t post your ViewSet
code, so I have to guess. But your model
should be set to User
and your lookup_field
should be set to username
.
Something like:
class UserViewSet(ModelViewSet):
model = User
lookup_field = "username"
- [Answered ]-Django app with Rails API
- [Answered ]-Is there a typical mod_wsgi project directory?
- [Answered ]-Filter Django queryset
- [Answered ]-Django Twoscoops and SECRET_KEY generation
- [Answered ]-How to display latest 5 posts by pub date?
Source:stackexchange.com