[Answer]-Displaying data from one model and using a form to update another associated by foreign key

1👍

Inspecting inlineformset_factory indicates that you can pass keyword argument extra=1 to cause it to generate one (rather than 3) inline forms as desired:

def inlineformset_factory(parent_model, model, form=ModelForm,
                      formset=BaseInlineFormSet, fk_name=None,
                      fields=None, exclude=None,
                      extra=3, can_order=False, can_delete=True, max_num=None,
                      formfield_callback=None):

Thus:

AnswerFormset = inlineformset_factory(Question, Answer, extra=1)

EDIT: Indeed, the extra keyword documentation confirms this: https://docs.djangoproject.com/en/dev/topics/forms/formsets/#formsets

Leave a comment