在Django的admin.py
中,为什么,即使这有效:
class StudentAdmin(UserAdmin):
add_form = UserCreationForm
form = CustomChangeForm
fieldsets = UserAdmin.fieldsets
这些不是吗?
class StudentAdmin(UserAdmin):
add_form = UserCreationForm
form = CustomChangeForm
def get_fieldsets(self, request, obj = None):
return UserAdmin.fieldsets
或
class StudentAdmin(UserAdmin):
add_form = UserCreationForm
form = CustomChangeForm
def get_fieldsets(self, request, obj = None):
return super(UserAdmin, self).get_fieldsets(request, obj)
它们不应该是等价的吗?
第二组给了我一个例外u"Key 'password' not found in Form"
,而第一组工作正常。
从长远来看,这一点显然是为了让更具体的事情发挥作用,但首先我想弄清楚到目前为止我遇到了什么。
同样,添加:
inlines = (MyInline,)
到班级工作。但补充一点:
def get_inline_instances(self, request, obj=None):
return (MyInline,)
抛出异常:unbound method get_formset() must be called with MyInline instance as first argument (got WSGIRequest instance instead)
。就我的理解而言,这两者也应该是等价的。
感谢。