3

我在尝试使用 POST 和 PUT 运行 CURL 时收到以下错误消息: {"error_message": "add() argument after * must be a sequence, not Task"

1)这是我正在尝试的命令:

$ curl --dump-header - -H "Content-Type:application/json" -X POST --data '{"tex
t":"create project plan","creator":"/user/user/2/"}' http://127.0.0.1:8000/task/
task/

2)这些是我的模型资源:(任务和用户是具有FK关系的两个模型)

class UserResource(ModelResource):
    tasks=fields.OneToManyField('challenge.api.TaskResource','tasks')
    class Meta:
        allowed_methods = ['get','delete','post']
        authorization= Authorization()
        queryset = User.objects.select_related().all()        
        include_resource_uri = False        
        filtering = {
            'user_id': ALL
        }    
class TaskResource(ModelResource):
    creator=fields.ForeignKey('task.api.UserResource','creator',related_name='tasks')
    class Meta:
        allowed_methods = ['get','post','put']
        authorization= Authorization()
        queryset=Task.objects.select_related().all()
        include_resource_uri = False
        fields = ['text']
        excludes = ['id']                
        filtering = {
            'creator': ALL_WITH_RELATIONS
        }

有没有人遇到过这个问题?有什么解决办法?任何帮助是极大的赞赏。在过去的三天里一直在尝试这个,但没有运气。Tastypie 文档不是那么好。

4

0 回答 0