'This piece of code lookup all ModelForm classes from forms.py
and record models as a dict key'

def prepare_modelforms(self):

    self._modelforms.clear()
    for app in settings.INSTALLED_APPS:
        _models = {}
        modforms = self._get_module(app, 'forms')
        if modforms:
            modname = ('%s.forms' % app)
            for c in dir(modforms):
                form = getattr(modforms, c)
                try:
                    subclass = issubclass(form, ModelForm)
                except TypeError:
                    continue
                if ((form.__module__ == modname) and subclass):
                    if (form._meta.model in _models):
                        if isinstance(_models[form._meta.model], dict):
                            _models[form._meta.model][form.__name__] = form
                        else:
                            tmp = _models[form._meta.model]
                            _models[form._meta.model] = {tmp.__name__: tmp, form.__name__: form}
                    else:
                        _models[form._meta.model] = form
        self._modelforms.update(_models)
