Created
August 4, 2016 15:38
-
-
Save JerzySpendel/06e99d1d5ea0c8a8f1fc5da5f1a2dc4d 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 TaggedItemSerializer(serializers.ModelSerializer): | |
def __init__(self, *args, **kwargs): | |
serializers.ModelSerializer.__init__(self, *args, **kwargs) | |
self.content_object = TaggedItemRelatedField(read_only=True, context=self.context) | |
tag = TagSerializer() | |
#content_object = TaggedItemRelatedField(read_only=True, context=self.context) wywalić | |
content_type = serializers.SerializerMethodField() | |
class Meta: | |
model = TaggedItem | |
fields = ('id', 'tag', 'content_type', 'content_object') | |
extra_kwargs = {'content_type': {'context': context}} | |
def get_content_type(self, obj): | |
return obj.content_type.model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment