Hope this helps:
This is the method that creates the forms in BaseFormSet:
def _construct_form(self, i, **kwargs): """ Instantiates and returns the i-th form instance in a formset. """ defaults = {'auto_id': self.auto_id, 'prefix': self.add_prefix(i)} if self.is_bound: defaults['data'] = self.data defaults['files'] = self.files if self.initial: try: defaults['initial'] = self.initial[i] except IndexError: pass
As you can see there is an attribute called "self.initial", it is passed as input to the newly created form. If you want to use _construct_form to add a new form and set custom source data, you must change "self.initial" before calling _construct_form. The initial one should be a dictionary, where the key is the name of the field and the value you want for your field.
source share