2012-12-21 36 views
1

我一直在使用實現代碼here,它在我部署的服務器上工作正常,在django-admin。服務器正在從一個較舊的django結賬(7cfe8e8fce)中運行。在我的本地機器上,我正在運行當前結帳(d407164c)。當試圖訪問的形式,我得到下面的錯誤,並給return線的基準:Django Admin _get_empty_form棄用?

def _get_empty_form(self, **kwargs): 
    return super(ParentInstInlineFormSet, self)._get_empty_form(parent_instance=self.instance) 
empty_form = property(_get_empty_form) 

錯誤文本:

'super' object has no attribute '_get_empty_form' 
Request Method: GET 
Request URL: http://localhost:8000/pmc/admin/pmc_log/reportperiod/add/ 
Django Version: 1.6.dev20121220194515 
Exception Type: AttributeError 
Exception Value:  
'super' object has no attribute '_get_empty_form' 
Exception Location: /software/django-pmc-daily-log/src/pmc_log/pmc_log/forms.py in _get_empty_form, line 18 

哪兒去_get_empty_form?什麼是最好的解決辦法?

回答

1

而不是使用私有方法_get_empty_form,我用@property裝飾。

@property 
def get_empty_form(self, **kwargs): 
    if self.instance is not None: 
     return super(ParentInstInlineFormSet, self).empty_form(parent_instance=self.instance) 
2

_get_empty_form開頭的_是一個相當不錯的指標,你不應該依賴它周圍 - 它看起來像它被刪除贊成使用empty_form財產。

嘗試修改您的代碼以調用父類的empty_form屬性。