2👍
It’s more complicated than you’d think to achieve this using that approach, because of the way in which Django uses metaclasses. (More details in this answer.)
I’d try overriding the constructor – (and note that the mixin extends from object now):
class MyFormMixin(object):
def __init__(self, *args, **kwargs):
super(MyFormMixin, self).__init__(*args, **kwargs)
self.fields['extra_field_1'] = forms.CharField(required=False)
self.fields['extra_field_2'] = forms.CharField(required=False)
class ModelFormA(MyFormMixin, forms.ModelForm):
...
Source:stackexchange.com