2011-08-18 38 views
4

我最後一次檢查,(H)一個參數:get_or_create()採用完全1個參數(2給出)

for entry in f['entries']: 
    h = {'feed':self, 'link': entry['link'],'title':entry['title'], 
     'summary':entry['summary'], 
     'updated_at':datetime.fromtimestamp(mktime(entry['updated_parsed']))} 

    en = Entry.objects.get_or_create(h) 

此代碼與在標題中的錯誤失敗。我能檢查?

回答

14

get_or_create只需關鍵字參數。如果參數是一個字典,你可以把它叫做:

en = Entry.objects.get_or_create(**h) 

或者,你可以直接把關鍵字參數:

en = Entry.objects.get_or_create(name=value, ....) 

你提供兩個參數的原因的錯誤消息告訴你的是有傳遞給函數的隱式self參數。

相關問題