Created
November 22, 2013 22:02
-
-
Save kevinw/7607631 to your computer and use it in GitHub Desktop.
This file contains 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 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