Created
March 5, 2018 21:49
-
-
Save ceoro9/09abe91eabc88c0ff4991d633753d525 to your computer and use it in GitHub Desktop.
Pass extra data to serialize model
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 PostSerializer(serializers.ModelSerializer): | |
field = serializers.SerializerMethodField() | |
def get_field(self, obj): | |
return self.obj.context['example] | |
serialize = PostSerializer(obj, context={'example': 'example'}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment