Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

add custom field to serializer

class FooSerializer(serializers.ModelSerializer):
  my_field = serializers.SerializerMethodField('is_named_bar')

  def is_named_bar(self, foo):
      return foo.name == "bar" 

  class Meta:
    model = Foo
    fields = ('id', 'name', 'my_field')
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #add #custom #field #serializer
ADD COMMENT
Topic
Name
4+5 =