我想在我的表单中通过程序排除一个字段。
目前我的代码是这样的:
class RandomForm(BaseForm):
def __init__(self, *args, **kwargs):
# This doesn't work
if kwargs["instance"] is None:
self._meta.exclude = ("active",)
super(ServiceForm, self).__init__(*args, **kwargs)
# This doesn't work either
if kwargs["instance"] is None:
self._meta.exclude = ("active",)
class Meta:
model = models.Service
fields = (...some fields...)
在创建新模型时,如何仅排除 active
字段?
self._meta.exclude = ("active",)
这行代码,该字段仍然会在表单中出现?还是你遇到了错误? - RalfRandomForm
真的在从ServiceForm
调用超类方法? - Ralf