'Magic happens here
We dynamically import the module based on app and model names
passed as view argument
From there we retrieve the ModelForm associated (which was discovered
previously on the auto_generate process)'

def add(self, request, mf=None):

    from freenasUI.freeadmin.navtree import navtree
    from freenasUI.freeadmin.views import JsonResp
    m = self._model
    app = self._model._meta.app_label
    context = {'app': app, 'model': m, 'modeladmin': m._admin, 'mf': mf, 'model_name': m._meta.model_name, 'verbose_name': m._meta.verbose_name, 'extra_js': m._admin.extra_js}
    if (not isinstance(navtree._modelforms[m], dict)):
        mf = navtree._modelforms[m]
    elif (mf is None):
        try:
            mf = navtree._modelforms[m][m._admin.create_modelform]
        except:
            try:
                mf = navtree._modelforms[m][m._admin.edit_modelform]
            except:
                mf = list(navtree._modelforms[m].values())[(-1)]
    else:
        mf = navtree._modelforms[m][mf]
    instance = m()
    formsets = {}
    if (request.method == 'POST'):
        mf = mf(request.POST, request.FILES, instance=instance)
        if m._admin.advanced_fields:
            mf.advanced_fields.extend(m._admin.advanced_fields)
        valid = True
        if m._admin.inlines:
            for inlineopts in m._admin.inlines:
                inline = inlineopts.get('form')
                prefix = inlineopts.get('prefix')
                formset = inlineopts.get('formset')
                _temp = __import__(('%s.forms' % app), globals(), locals(), [inline], 0)
                inline = getattr(_temp, inline)
                if formset:
                    formset = getattr(_temp, formset)
                else:
                    formset = FreeBaseInlineFormSet
                extrakw = {'can_delete': False}
                fset_fac = inlineformset_factory(m, inline._meta.model, form=inline, formset=formset, extra=0, **extrakw)
                try:
                    fsname = ('formset_%s' % (inline._meta.model._meta.model_name,))
                    fset = fset_fac(request.POST, prefix=prefix, parent=mf, instance=instance)
                    formsets[fsname] = {'instance': fset, 'position': inlineopts.get('position', 'bottom')}
                except dforms.ValidationError:
                    pass
        for (name, fsinfo) in list(formsets.items()):
            for frm in fsinfo['instance'].forms:
                valid &= frm.is_valid()
            valid &= fsinfo['instance'].is_valid()
        valid &= mf.is_valid(formsets=formsets)
        if valid:
            if ('__confirm' not in request.POST):
                message = self.get_confirm_message('add', obj=instance, form=mf)
                if message:
                    return JsonResp(request, confirm=self.confirm(message))
            try:
                mf.save()
                for (name, fsinfo) in list(formsets.items()):
                    fsinfo['instance'].save()
                events = []
                if (hasattr(mf, 'done') and callable(mf.done)):
                    mf.done(request=request, events=events)
                return JsonResp(request, form=mf, formsets=formsets, message=(_('%s    successfully    updated.') % (m._meta.verbose_name,)), events=events)
            except MiddlewareError as e:
                return JsonResp(request, error=True, message=(_('Error:    %s') % str(e)))
            except ServiceFailed as e:
                return JsonResp(request, error=True, message=_('The    service    failed    to    restart.'))
        else:
            return JsonResp(request, form=mf, formsets=formsets)
    else:
        mf = mf()
        if m._admin.advanced_fields:
            mf.advanced_fields.extend(m._admin.advanced_fields)
        if m._admin.inlines:
            extrakw = {'can_delete': False}
            for inlineopts in m._admin.inlines:
                inline = inlineopts.get('form')
                prefix = inlineopts.get('prefix')
                formset = inlineopts.get('formset')
                _temp = __import__(('%s.forms' % app), globals(), locals(), [inline], 0)
                inline = getattr(_temp, inline)
                if formset:
                    formset = getattr(_temp, formset)
                else:
                    formset = FreeBaseInlineFormSet
                fset_fac = inlineformset_factory(m, inline._meta.model, form=inline, formset=formset, extra=1, **extrakw)
                fsname = ('formset_%s' % (inline._meta.model._meta.model_name,))
                fset = fset_fac(prefix=prefix, instance=instance, parent=mf)
                fset.verbose_name = inline._meta.model._meta.verbose_name
                formsets[fsname] = {'instance': fset, 'position': inlineopts.get('position', 'bottom')}
    context.update({'form': mf, 'formsets': formsets})
    context.update(self.get_extra_context('add', request=request, form=mf))
    template = ('%s/%s_add.html' % (m._meta.app_label, m._meta.object_name.lower()))
    try:
        get_template(template)
    except TemplateDoesNotExist:
        template = 'freeadmin/generic_model_add.html'
    return render(request, template, context)
