如何在django Rest中通过令牌获取用户

时间:2016-08-31 20:44:16

标签: python django django-rest-framework

使用:

class PostSerializer(serializers.ModelSerializer):
    author = ExtUserSerializer(required=False, allow_null=True)
    class Meta:
        model = Post
        field = ('title','description','rating','author')
    def create(self, validated_data):
        return Post.objects.create(**validated_data)

@api_view(['GET'])
def post_list(request, format=None):
if request.method == 'GET':
    posts = Post.objects.all()
    serializer = PostSerializer(posts, many=True)

    return Response(serializer.data)

如何修改Serializer并查看以自动填写字段作者

0 个答案:

没有答案