Quantcast
Viewing all articles
Browse latest Browse all 41

Answer by Amir Afianian for Django: Get User profile from User serializer

The easiest way is to put, for showing profile data is to put depth = 1 in class Meta of your serializer as follows:

class CurrentUserSerializer(serializers.ModelSerializer):    groups = GroupSerializer(many=True)    class Meta:        model = User        fields = ('username', 'email', 'first_name', 'last_name', 'groups')        depth = 1     def to_representation(self, instance):        return {'username': instance.username,'email': instance.email,'first_name': instance.first_name,'last_name': instance.last_name,'groups':  GroupSerializer(instance.groups.all(), many=True).data,        }

Viewing all articles
Browse latest Browse all 41

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>