【问题标题】:Django Admin _get_empty_form deprecated?Django Admin _get_empty_form 已弃用?
【发布时间】:2012-12-21 17:20:10
【问题描述】:

我一直在使用找到here 的代码,它在django-admin 中部署的服务器上运行良好。服务器从 django (7cfe8e8fce) 的旧结帐运行。在我的本地机器上,我正在运行当前结帐 (d407164c)。尝试访问该表单时,我收到以下错误以及对 return 行的引用:

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 去哪儿了?最好的解决方法是什么?

【问题讨论】:

    标签: django django-forms django-admin


    【解决方案1】:

    _get_empty_form 开头的 _ 是一个很好的指标,表明您不应该依赖它存在 - 看起来它已被删除以支持使用 empty_form 属性。

    尝试修改代码以调用父类的empty_form 属性。

    【讨论】:

      【解决方案2】:

      我没有使用私有方法_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)
      

      【讨论】:

        猜你喜欢
        • 2021-07-07
        • 1970-01-01
        • 2016-06-13
        • 2014-02-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多