@register.simple_tag
def bmffield(field):
    if isinstance(field.field, forms.models.ModelMultipleChoiceField):
        return field.as_widget(attrs={'class': 'form-control'})

    elif isinstance(field.field, forms.models.ModelChoiceField):
        model = field.field.choices.queryset.model
        if hasattr(model, "_bmfmeta"):
            value = field.value()
            if value:
                try:
                    text = field.field.choices.queryset.get(pk=field.value())
                except field.field.choices.queryset.model.DoesNotExist:
                    text = None
                    value = None
            else:
                text = None

            if field.field.widget.attrs.get('readonly', False):
                data = '<p class="form-control-static">%s</p>' % (text or '<i>%s</i>' % _('empty'))
                data += field.as_hidden(attrs={'autocomplete': 'off', 'value': value})
                return data
            else:
                data = '<div class="input-group" data-bmf-autocomplete="1">'
                data += field.as_text(attrs={
                    'class': 'form-control',
                    'id': '%s-value' % field.auto_id,
                    'placeholder': text or "",
                    'autocomplete': 'off',
                    'name': '',
                })
                data += '</div>'
                data += field.as_hidden(attrs={'autocomplete': 'off'})
                return data
        else:
            # TODO: this manages relationsships to non-django models. it makes propably
            # sense to implement a search-function for django models like user
            return field.as_widget(attrs={'class': 'form-control'})

    elif isinstance(field.field, forms.DateTimeField):
        data = '<div class="input-group" data-bmf-calendar="dt">'
        data += field.as_widget(attrs={'class': 'form-control', 'autocomplete': 'off'})
        data += '</div>'
        return data
    elif isinstance(field.field, forms.DateField):
        data = '<div class="input-group" data-bmf-calendar="d">'
        data += field.as_widget(attrs={'class': 'form-control', 'autocomplete': 'off'})
        data += '</div>'
        return data
    elif isinstance(field.field, forms.TimeField):
        data = '<div class="input-group" data-bmf-calendar="t">'
        data += field.as_widget(attrs={'class': 'form-control', 'autocomplete': 'off'})
        data += '</div>'
        return data
    else:
        return field.as_widget(attrs={'class': 'form-control'})
dataset/ETHPy150Open django-bmf/django-bmf/djangobmf/templatetags/djangobmf_forms.py/bmffield/original