我正在尝试覆盖ModelAdmin的表单字段,如下所示:
class MyModelAdmin(admin.ModelAdmin):
def get_form(self, *args, **kwargs):
form = super(MyModelAdmin, self).get_form(*args, **kwargs)
form.fields['password'].help_text = "..."
return form
我收到属性错误:“类型对象'FailedLoginForm'没有属性'fields'”。
不是ModelAdmin.get_form()返回一个常规的Django表单对象。怎么没有字段?
答案 0 :(得分:1)
我建议您只是覆盖您想要的表单。
class UserCreationForm(UserCreationForm):
# we want to use the email as the username
def __init__(self, *args, **kwargs):
super(UserCreationForm, self).__init__(*args, **kwargs)
# let's require these fields
self.fields['email'].required = True
self.fields['first_name'].required = True
self.fields['last_name'].required = True
# let's not require these
self.fields['username'].required = False
self.fields['password1'].required = False
self.fields['password2'].required = False
从那里你可以做任何你想做的事。