Django:覆盖 ModelAdminForm 的字段属性
我试图覆盖 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’没有属性‘字段’”。
ModelAdmin.get_form() 不是返回常规 Django 表单对象吗?怎么没有字段呢?
I am trying to override a ModelAdmin's form field as below:
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
I am getting an Attribute error: "type object 'FailedLoginForm' has no attribute 'fields'".
Isn't ModelAdmin.get_form() returning a regular Django form object. How come it doesn't have fields?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您只需覆盖您想要的表单即可。
从那里你几乎可以做任何你想做的事情。
I suggest that you simply override the form that you want.
From there you can do pretty much anything you want.