在 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)
. 据我了解,这两者也应该是等价的。
谢谢。