Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to post data to foreign key in django rest framework

class ProfileSerializer(serializers.ModelSerializer):
    class Meta:
        model=Profile
        fields=('id','user','email','birthday','gender','bio','points')
        read_only_fields = ('created','updated')

    def to_representation(self, instance):
        self.fields['user'] =  UserSerializer(read_only=True)
        return super(ProfileSerializer, self).to_representation(instance)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #post #data #foreign #key #django #rest #framework
ADD COMMENT
Topic
Name
2+3 =