Hi all,
I have created a formset:
ActivityStepFormSet = inlineformset_factory(
Activity,
ActivityStep,
form=ActivityStepForm, # this is ModelForm
extra=0, # number of extra empty forms to display
min_num=1, # number of minimum filled forms
can_delete=False, # show a checkbox in each form to delete the row
)
The form is shown, I added a new row (form in the formset through javascript), updated TOTAL-FORMS to 2. When the form is posted, I receive the POST data, and I provide the following kwargs to initialise an ActivityStepFormSet ():
formset_kwargs: {'data': <QueryDict: {'csrfmiddlewaretoken': ['zFzWtsyT5IynU4auVsLE1jhuvc2BrvoFknLEQSHpzactEZ28rfGQcCkWPi0sZ1Cq'], 'activity_digitisation_wizard_view-current_step': ['add_activity'], 'add_activity-name': ['Sample Activity 1'], 'add_activity-description': [''], 'add_activity-name_local': [''], 'add_activity-description_local': [''], 'add_activity-language_local': [''], 'add_activity-created_by': ['2'], 'add_activity-TOTAL_FORMS': ['2'], 'add_activity-INITIAL_FORMS': ['0'], 'add_activity-MIN_NUM_FORMS': ['1'], 'add_activity-MAX_NUM_FORMS': ['1000'], 'add_activity-__prefix__-created_by': [''], 'add_activity-0-created_by': ['2'], 'add_activity-1-created_by': [''], 'add_activity-__prefix__-name': [''], 'add_activity-__prefix__-description': [''], 'add_activity-__prefix__-name_local': [''], 'add_activity-__prefix__-description_local': [''], 'add_activity-__prefix__-language_local': [''], 'add_activity-__prefix__-activity': [''], 'add_activity-__prefix__-stimulus': [''], 'add_activity-__prefix__-id': [''], 'add_activity-0-name': ['help'], 'add_activity-0-description': [''], 'add_activity-0-name_local': [''], 'add_activity-0-description_local': [''], 'add_activity-0-language_local': [''], 'add_activity-0-activity': [''], 'add_activity-0-stimulus': ['1'], 'add_activity-0-id': [''], 'add_activity-1-name': ['help2'], 'add_activity-1-description': [''], 'add_activity-1-name_local': [''], 'add_activity-1-description_local': [''], 'add_activity-1-language_local': [''], 'add_activity-1-activity': [''], 'add_activity-1-stimulus': ['1'], 'add_activity-1-id': [''], '_next': ['Next']}>, 'files': <MultiValueDict: {}>, 'prefix': 'add_activity', 'initial': [{'created_by': <SimpleLazyObject: <User: petasis>>}, {'created_by': <SimpleLazyObject: <User: petasis>>}]}
However, calling is_valid() on the form object, returns false:
False [{}, {'created_by': ['This field is required.']}]
I cannot understand why the second form is invalid, since I have provided a list of two “created_by” in the argument ‘initial’.
What can be wrong?