I have the following code:
from form_utils import forms as betterforms
from django.db import models
class FilterForm(betterforms.BetterForm):
def __init__(self, *args, **kwargs):
super(FilterForm, self).__init__(*args, **kwargs)
print('filter form __init__')
...
class NewEntityForm(FilterForm, FileFormMixin):
def __init__(self, *args, **kwargs):
super(NewEntityForm, self).__init__(*args, **kwargs)
# super(FileFormMixin, self).__init__() <-- really does not matter
print('newentityform __init__')
FileForMixin defined as follows:
class FileFormMixin(object):
def __init__(self, *args, **kwargs):
super(FileFormMixin, self).__init__(*args, **kwargs)
print('file form mixin __init__')
FileFormMixin
is provided by https://github.com/mbraak/django-file-form, betterforms by https://github.com/carljm/django-form-utils.
The problem is, FileFormMixin
's __init__
is never getting called. How can I fix that? I really need all of them. Right now it's executing only FilterForm
and NewEntityForm
constructors.
UPDATE
So, I looked at all mentioned classes __init__
's, and they're calling super()!
FileFormMixin
:
class FileFormMixin(object):
def __init__(self, *args, **kwargs):
super(FileFormMixin, self).__init__(*args, **kwargs)
BetterForm
:
class BetterBaseForm(object):
...
def __init__(self, *args, **kwargs):
self._fieldsets = deepcopy(self.base_fieldsets)
self._row_attrs = deepcopy(self.base_row_attrs)
self._fieldset_collection = None
super(BetterBaseForm, self).__init__(*args, **kwargs)
class BetterForm(with_metaclass(BetterFormMetaclass, BetterBaseForm),
forms.Form):
__doc__ = BetterBaseForm.__doc__
More of that, printing class' mro as @elwin-arens proposed, gives following output:
filter form __init__
NewEntityForm.__mro__ (<class 'myapp.forms.NewEntityForm'>, <class 'myapp.forms.FilterForm'>, <class 'form_utils.forms.BetterForm'>, <class 'django.forms.widgets.NewBase'>, <class 'form_utils.forms.BetterBaseForm'>, <class 'django.forms.forms.Form'>, <class 'django.forms.forms.BaseForm'>, <class 'django_file_form.forms.FileFormMixin'>, <class 'object'>)
newsiteform __init__
But __init__
for FileFormMixin is executed only if I call it explicitly as @tom-karzes advised