Tastypie:为什么在执行PUT时“pk”字段会响应?

时间:2012-09-05 19:01:46

标签: django tastypie

我有这个ModelResource:

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 /项目时,响应是:

'{
"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 /项目响应是:

'{
"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时存在。有任何想法吗? 感谢。

0 个答案:

没有答案