Testing InlineFormset clean methods

我的梦境 提交于 2019-12-05 05:48:55
Suganthi

You can use the inlineformset_factory method from django.forms.models to create a custom inline formset. This method sets the fk value to your formset based on the parent class passed on to it.

structure = StructureFactory() #foreign key
data = {'form-TOTAL_FORMS': '1', 'form-INITIAL_FORMS': '0', 'form-MAX_NUM_FORMS': '', 'form-0-field1':'good-value', … }
BIFormset = inlineformset_factory(Structure, Bracket, formset=BracketInlineFormset)
formset = BIFormset(data, prefix='form', instance=structure) 
self.assertTrue(formset.is_valid())

Note the formset=BracketInlineFormset parameter while constructing the formset with the factory.

Reference: Django Docs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!