1 回答

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超9個(gè)贊
你絕對可以做到!這是您的“編輯”表單的更新版本,帶有更新按鈕的自定義 init 方法Submit:
class MySecondForm(MyForm):
field_1 = forms.CharField()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['field_1'].widget.attrs['readonly'] = True
# From crispy_forms.layout.Layout.__init__, it sets up self.fields
# as a list, which we can now alter b/c they've been created in the
# parent class. Let's target the Submit() item, which is the last
# item in layout.fields:
self.helper.layout.fields[-1].value = "Save Changes"
添加回答
舉報(bào)