Created
July 22, 2019 20:15
-
-
Save akshar-raaj/abc23097f5e2f2c4d755af3ae35131ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UserSerializer(serializers.ModelSerializer): | |
| groups = serializers.SerializerMethodField() | |
| def get_groups(self, obj): | |
| groups = obj.groups.all() | |
| if not groups: | |
| return None | |
| return GroupSerializer(groups, many=True).data | |
| class Meta: | |
| model = User | |
| fields = ('email', 'first_name', 'last_name', 'groups') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment