Created
September 27, 2017 17:00
-
-
Save vitorfs/3c228824067815970ccea66cba27ae18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import template | |
register = template.Library() | |
@register.filter('fieldtype') | |
def fieldtype(field): | |
return field.field.widget.__class__.__name__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load fieldtype %} | |
{% for hidden in form.hidden_fields %} | |
{{ hidden }} | |
{% endfor %} | |
{% for field in form.visible_fields %} | |
<div class="form-group{% if field.errors %} has-error{% endif %}"> | |
{% if field|fieldtype == 'CheckboxInput' %} | |
<div class="col-md-10 col-md-offset-2 col-sm-8 col-sm-offset-4"> | |
<div class="checkbox"> | |
<label> | |
{{ field }} {{ field.label }} | |
</label> | |
</div> | |
{% for error in field.errors %} | |
<p class="help-block">{{ error }}</p> | |
{% endfor %} | |
<span class="help-block">{{ field.help_text }}</span> | |
</div> | |
{% else %} | |
<label for="{{ field.id_for_label }}" class="col-md-2 col-sm-4 control-label">{{ field.label }}</label> | |
<div class="col-md-10 col-sm-8"> | |
{{ field }} | |
{% for error in field.errors %} | |
<p class="help-block">{{ error }}</p> | |
{% endfor %} | |
{% if field.help_text %} | |
<span class="help-block">{{ field.help_text }}</span> | |
{% endif %} | |
</div> | |
{% endif %} | |
</div> | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment