Django 1.9 form inheritance on UpdateView
<p>The problem i have is with a single field that i added. </p>

<p>I have my form:</p>

<pre><code>

    class employeesForm(forms.ModelForm):
        class Meta:
            fields = [
                'num_employee',
                'id_ignition',
                'fullName',
                'shortName',
                'salary',
                'gender',
                'rfc',
                'imss',
                'curp',
                'birthday',
                'initday',
                'id_costCenter',
                'id_jobCode',
                'id_status',
                'nationality',
                'picture',
                'source',
            ]


            widgets = {
                'num_employee': forms.NumberInput(attrs={'class': 'form-control', 'name': 'num_employee'}),
                'id_ignition': forms.NumberInput(attrs={'class': 'form-control', 'name': 'id_ignition'}),
                'fullName': forms.TextInput(attrs={'class': 'form-control', 'name': 'fullName', 'placeholder': 'Angel Rafael Ortega Vazquez'}),
                'shortName': forms.TextInput(attrs={'class': 'form-control', 'name': 'shortName', 'placeholder': 'Rafael Ortega'}),
                'salary': forms.NumberInput(attrs={'class': 'form-control', 'name': 'salary', 'placeholder': '5000'}),
                'gender': forms.CheckboxInput(attrs={'class': 'form-control', 'name': 'gender'}),
                'rfc': forms.TextInput(attrs={'class': 'form-control', 'name': 'rfc', 'id': 'rfc'}),
                'imss': forms.TextInput(attrs={'class': 'form-control', 'name': 'imss', 'id': 'imss'}),
                'curp': forms.TextInput(attrs={'class': 'form-control', 'name': 'curp'}),
                'birthday': forms.DateInput(attrs={'class': 'form-control', 'name': 'birthday'}),
                'initday': forms.DateInput(attrs={'class': 'form-control', 'name': 'initday'}),
                'id_costCenter': forms.Select(attrs={'class': 'form-control', 'name': 'id_costCenter'}),
                'id_jobCode': forms.Select(attrs={'class': 'form-control', 'name': 'id_jobCode'}),
                'id_status': forms.Select(attrs={'class': 'form-control', 'name': 'id_status'}),
                'nationality': forms.Select(attrs={'class': 'form-control', 'name': 'nationality'}),
                'picture': forms.ClearableFileInput(attrs={'class': 'form-control', 'name': 'picture'}),
                'source': forms.Select(attrs={'class': 'form-control', 'name': 'source'}),
            }

</code></pre>

<p>In my model I have an extra field (antiquity), but Iâm ignoring it here because in my CreateView i populate that field based in other parameters (antiquity = initday).</p>

<p>Everything worked fine until I needed to create an UpdateView with that extra field pre-populated, what I did was to inherit the previews form and adding that extra field:</p>

<pre><code>

    class Enhanced_employeesForm(employeesForm):

        antiquity = forms.CharField(
            widget=forms.DateInput(attrs={'class': 'form-control', 'name': 'antiquity'}))

</code></pre>

<p>It did the thing, the input field is rendered in my template, but while everything is pre-populated with the info based in the id, my antiquity field is empty.</p>

<p>Thatâs the only thing Iâm missing in my configuration, because django even detect when that field is empty on the submit and prevent any update to the database</p>

<p>I tried doing something like:</p>

<pre><code>form.antiquity(instance=Employees.objects.get(pk=self.kwargs['pk']))
</code></pre>

<p>But the error says that 'Enhanced_employeesForm' object has no attribute 'antiquity'.</p>

<p>I was doing it wrong, i had to add this code into my enhanced form:</p>

<pre><code>class Enhanced_employeesForm(employeesForm):
    class Meta(employeesForm.Meta):
        employeesForm.Meta.fields += ['antiquity']
</code></pre>

<p>and that made the thing.</p>

<p>if you need widgets you might noticed that everything is overriden, to prevent that you'll need this:</p>

<pre><code>employeesForm.Meta.widgets['antiquity'] = forms.DateInput(attrs={'class': 'form-control'})
</code></pre>

python inheritance django-forms django-views django-1.9