开发者

django - disable field validaton in form

开发者 https://www.devze.com 2023-03-21 11:30 出处:网络
I need to disable field validation in ModelForm. I want this validation not to validate some field. I have some situations (AJAX rendering form) when I want to return more complex form with additional

I need to disable field validation in ModelForm. I want this validation not to validate some field. I have some situations (AJAX rendering form) when I want to return more complex form with additional fields. I pass POST to the form and render new one with post fields saved. Some new fields are added and they can't be validated. I pass flag to form and recognize when it happens. Should I ma开发者_如何转开发ke it in some clean functions?


Just override the validation function with empty function

previousReportIdNotEqual=forms.MultipleChoiceField(required=False)

def empty(self):
    pass

previousReportIdNotEqual.validate=empty


If the model field has blank=True, then required is set to False on the form field. Otherwise, required=True.

0

精彩评论

暂无评论...
验证码 换一张
取 消