How about…..
On your MemberSerializer, define a field on it like:
groups = MembershipSerializer(source="membership_set", many=True)
and then on your membership serializer you can create this:
class MembershipSerializer(serializers.HyperlinkedModelSerializer):
id = serializers.Field(source="group.id")
name = serializers.Field(source="group.name")
class Meta:
model = Membership
fields = ('id', 'name', 'join_date', )
That has the overall effect of creating a serialized value, groups, that has as its source the membership you want, and then it uses a custom serializer to pull out the bits you want to display.
EDIT: as commented by @bryanph, serializers.field
was renamed to serializers.ReadOnlyField
in DRF 3.0, so this should read:
class MembershipSerializer(serializers.HyperlinkedModelSerializer):
id = serializers.ReadOnlyField(source="group.id")
name = serializers.ReadOnlyField(source="group.name")
class Meta:
model = Membership
fields = ('id', 'name', 'join_date', )
for any modern implementations