2012-02-16 7 views
3

PUTを実行して外部キーフィールドをnullにすると、Tastypieでオブジェクトに変更が保存されないという問題が発生します。ここで TastypieはPUT中に外部キー参照を削除しません

は私ModelResourceです:

class FolderResource(ModelResource): 
    parent = fields.ForeignKey('self','parent',full=True,default=None,blank=True,null=True) 
    project = fields.ForeignKey(ProjectResource,'project',full=False) 
    class Meta: 
     queryset = Folder.objects.all() 
     authentication = Authentication() 
     authorization = Authorization() 
     resource_name = 'folder' 
     include_absolute_url = True 
     always_return_data = True 
     filtering = { 
      "slug": ('exact', 'startswith',), 
      "name": ALL, 
      "project":ALL_WITH_RELATIONS, 
      "parent":ALL_WITH_RELATIONS, 
      "id":('exact') 
      } 

I持って、次のデータを既存のフォルダオブジェクト:

{ 
    absolute_url: "/projects/1/files/5/", 
    created_date: "13 Feb 2012", 
    id: "5", 
    modified_date: "15 Feb 2012", 
    modified_file: null, 
    name: "testfolder2", 
    parent: { 
     absolute_url: "/projects/1/files/1/", 
     created_date: "4 Feb 2012", 
     id: "1", 
     modified_date: "15 Feb 2012", 
     modified_file: null, 
     name: "testfolder1", 
     parent: null, 
     project: "/projects/api/v1/project/1/", 
     removed_date: null, 
     resource_uri: "/projects/api/v1/folder/1/", 
     slug: "testfolder1" 
    }, 
    project: "/projects/api/v1/project/1/", 
    removed_date: null, 
    resource_uri: "/projects/api/v1/folder/5/", 
    slug: "testfolder2" 
} 

私は/プロジェクト/ API/V1」に次のデータをPUTしようとします/フォルダ/ 5/':

{ 
    parent: null 
} 

エラーは戻っていませんが、何も問題はありませんが、何も保存されませんデータベース。誰かが私が間違っていることや変更が保存されていない理由を教えてもらえますか?

+0

運がいいですか?私は同じ問題を抱えています。 – djsmith

+0

同じです... NamespacedModelResourceの使用btw。 PATCHを使用している間は動作させることはできません。 parent:この例のnullは空の親を作るだけです: – gabn88

答えて

0

部分的な更新を行う場合は、PATCHメソッドが必要です。

関連する問題