[Django]-Can't initialise ModelForm fields on bound form?

5👍

I think you want to set the initial value of a field from other model field value if it is None:

def __init__(self, *args, **kwargs):
    super(MyModelForm, self).__init__(*args, **kwargs)

    if self.instance.pk:
        if not self.initial.get('my_field'):
            self.initial['my_field'] = self.instance.parent.my_field

Leave a comment