我制作了一个名为Fooinline的内联版。这个内联在Django 1.02中工作正常,但是当我升级到Django 1.1时它开始出错:
**TypeError at /admin/casd/aaas/4028cb901dd9720a011deadd85e8007f/
__init__() got an unexpected keyword argument 'request'**
我的Fooinline
代码是:
class FooInline(InlineModelAdmin):
template = 'admin/edit_inline/tabular2.html'
def formfield_for_dbfield(self,db_field, **kwargs):
# if isinstance(db_field, (models.ForeignKey, models.ManyToManyField)):
# BaseModelAdmin.formfield_for_dbfield(self, db_field, **kwargs)
# else:
kwargs['widget'] = FlatTextWidget
return db_field.formfield(**kwargs)
我的FlatTextWidget
是
class FlatTextWidget(HiddenInput):
def __init__(self, attrs=None):
if attrs is not None:
self.attrs = attrs.copy()
super(Widget, self).__init__(attrs)
else:
self.attrs = {}
super(Widget, self).__init__()
def render(self, name, value, attrs=None):
real_field = super(HiddenInput, self).render(name, value, attrs)
x = value
if x is None:
x = ''
return mark_safe( '%s%s' % (real_field, x) )
def _has_changed(self, initial, data):
return False
我将Fooinline
称为
class XYZInline(Fooinline):
model=XYZ
答案 0 :(得分:2)
错误在formfield_for_dbfield
中,应该是:
def formfield_for_dbfield(self, db_field, **kwargs):
kwargs['widget'] = FlatTextWidget
return super(FooInline, self).formfield_for_dbfield(db_field,**kwargs)
中的原始功能