def _model_select_field(self, prop, multiple, remote_model, **kwargs):
        loader = getattr(self.view, '_form_ajax_refs', {}).get(prop.key)

        if loader:
            if multiple:
                return AjaxSelectMultipleField(loader, **kwargs)
            else:
                return AjaxSelectField(loader, **kwargs)

        if 'query_factory' not in kwargs:
            kwargs['query_factory'] = lambda: self.session.query(remote_model)

        if 'widget' not in kwargs:
            if multiple:
                kwargs['widget'] = form.Select2Widget(multiple=True)
            else:
                kwargs['widget'] = form.Select2Widget()

        if multiple:
            return QuerySelectMultipleField(**kwargs)
        else:
            return QuerySelectField(**kwargs)
dataset/ETHPy150Open mrjoes/flask-admin/flask_admin/contrib/sqla/form.py/AdminModelConverter._model_select_field/original