class GroupSerializer(serializers.ModelSerializer):


    class Meta:
        model = Group
fields = 'name',


class UserSerializer(serializers.ModelSerializer):
    groups = GroupSerializer(many=True)


class Meta:
    model = User
How to serialize groups of a user with Django-Rest-Framework