Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

django rest framework get foreign key object

class PostSerializer(serializers.ModelSerializer):
    user = serializers.PrimaryKeyRelatedField(queryset=User.objects.all())

    class Meta:
        model = Post
        fields = ('id', 'user', 'comment')
Source by sakataharumi.hatenablog.jp #
 
PREVIOUS NEXT
Tagged: #django #rest #framework #foreign #key #object
ADD COMMENT
Topic
Name
9+1 =