Skip to content

Instantly share code, notes, and snippets.

@kevinw
Created November 22, 2013 22:02
Show Gist options
  • Save kevinw/7607631 to your computer and use it in GitHub Desktop.
Save kevinw/7607631 to your computer and use it in GitHub Desktop.
class RelatedModelSerializer(serializers.ModelSerializer):
def to_native(self, obj):
ret = super(RelatedModelSerializer, self).to_native(obj)
ret = {
'result': ret
}
for field_name, field in self.get_default_fields():
if instanceof(field, PrimaryKeyRelatedField):
pluralized = field_name + 's'
if not pluralized in ret:
ret[pluralized] = []
ret[pluralized].append(
# field is a PrimaryKeyRelatedField. how do I do the object lookup and unserialize it?
)
return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment