From the comment by @karthikr i see where i was going wrong. I originally thought you had to validate each form in a formset individually, but formset.is_valid() covers each form so as long as you save the form after all formset checks then it should be okay.if form1.is_valid(): if formset.is_valid(): form1_obj = form1.save() for form in formset: form_obj = form.save(commit=False) form_obj.foreign_key = form1_obj form_obj.save() 这篇关于在检查另一个表单集的有效性之前保存模型(对于外键)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-02 00:51