Skip to content

Instantly share code, notes, and snippets.

@JerzySpendel
Created August 4, 2016 15:38
Show Gist options
  • Save JerzySpendel/06e99d1d5ea0c8a8f1fc5da5f1a2dc4d to your computer and use it in GitHub Desktop.
Save JerzySpendel/06e99d1d5ea0c8a8f1fc5da5f1a2dc4d to your computer and use it in GitHub Desktop.
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