1

我有这个模型资源:

class ProjectResource(ModelResource):
    id = fields.IntegerField('id', readonly=True)

    def alter_list_data_to_serialize(self, request, data):
        return data['objects']


    class Meta:
        queryset = Project.objects.all()
        list_allowed_methods = ['get', 'post']
        detail_allowed_methods = ['get', 'post', 'put', 'delete']
        resource_name = 'projects'
        include_resource_uri = False
        #fields = ['id', 'title', 'date_created', 'date_modified']
        excludes = []
        always_return_data = True

        authorization = Authorization()

当我做 GET /projects/1 或 POST /projects 响应是:

'{
"date_created": "2012-08-29T16:47:55.417000+00:00", 
"date_modified": "2012-08-29T16:47:55.417000+00:00", 
"id": 1, 
"title": "1st Testing Project"
}'

但是当我做 PUT /projects 响应是:

'{
"date_created": "2012-08-29T16:47:55.417000+00:00", 
"date_modified": "2012-09-05T18:58:39.746336+00:00", 
"id": 1, 
"pk": "1", 
"title": "EDITED project"
}'

所以有额外的“pk”字段。它是如何到达那里的?我该如何摆脱它?它仅在执行 PUT 时存在。有任何想法吗?谢谢。

4

0 回答 0