Skip to content

Instantly share code, notes, and snippets.

@akshar-raaj
Created July 22, 2019 20:03
Show Gist options
  • Select an option

  • Save akshar-raaj/2a2a34ef9d450eb3a48f77b270d18ce9 to your computer and use it in GitHub Desktop.

Select an option

Save akshar-raaj/2a2a34ef9d450eb3a48f77b270d18ce9 to your computer and use it in GitHub Desktop.
class GroupSerializer(serializers.ModelSerializer):
class Meta:
model = Group
fields = ('id', 'name')
class UserSerializer(serializers.ModelSerializer):
all_groups = GroupSerializer(source='groups', many=True)
class Meta:
model = User
fields = ('email', 'first_name', 'last_name', 'all_groups')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment