It's a bit odd but I would like to define some properties of a form field like its widget or class from the model definition. I know it is easy from the form but I'd like to know if it's possible from the model. I'm not sure but I think I remember having seen something like that some day.
问问题
50 次
1 回答
-1
好吧,您可以创建自己的模型字段子类并重新定义它们的formfield
方法以添加您想要的属性,但可能不值得付出努力,因为您将被覆盖。然而,那是小时电话。
无论如何,如果您决定尝试此操作,请确保遵循文档中的这两个部分:
ModelForms 和自定义字段
以及
将模型字段的表单字段指定为默认实现Field.formfield
做一些您通常不想做的重要事情忽略。
于 2012-05-04T23:21:51.487 回答