开发者

Django formset - validate one of the forms, not all

开发者 https://www.devze.com 2023-04-02 17:56 出处:网络
I have a formset that generates two forms that have different initial values. When the user submits the form, they\'re only going to fill out one of them, not both. These initial values get populated

I have a formset that generates two forms that have different initial values. When the user submits the form, they're only going to fill out one of them, not both. These initial values get populated in the view, which (I think) means FormSet can't figure out if they've changed or not, so default validation fails. But really, all I care abo开发者_JAVA百科ut is if one of them is valid. I'd like to take that valid form and process it. What's the best way to go about this?


Not only formset.is_valid() exists, but also

for form in formset.forms:
  if form.is_valid():
    ..

should work.

0

精彩评论

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