Skip to content

Instantly share code, notes, and snippets.

@ErDmKo
Created February 10, 2014 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ErDmKo/8918792 to your computer and use it in GitHub Desktop.
Save ErDmKo/8918792 to your computer and use it in GitHub Desktop.
Select, radio and checkbox customization django
#change standart widget to choice inputs https://github.com/django/django/blob/master/django/forms/widgets.py#L577
class MyForm(forms.ModelForm):
class Meta:
model = office_models.myForm
fields = ['education', 'occupation', 'post', \
'neighborhood', 'man_count', 'with_animals']
widgets = {
'education': forms.RadioSelect,
'occupation': forms.RadioSelect,
'with_animals': forms.CheckboxInput(attrs={'class':'on_off'})
}
{% with choice_list=form.education %}
{% include 'widgets/custom_select.html' %}
{% endwith %}
{% for radio in choices %}
<li><input type="{{ type }}"
name="{{ radio.name }}"
id="{{ radio.name }}_{{ radio.choice_value }}"
value="{{ radio.choice_value }}"
{% if radio.is_checked %} checked="checked"{% endif %}/>
<label for="{{ radio.name }}_{{ radio.choice_value }}">{{ radio.choice_label }}</label></li>
{% endfor %}
<dl class="custom_select">
<dt alt="{{ choice_list.0.choice_value }}">
{% with radio=choice_list.0 %}
{{ radio.choice_label }}
{% endwith %}
</dt>
<dd>
{% with choices=choice_list type="radio" %}
{% include 'widget_input_list.html' %}
{% endwith %}
</dd>
</dl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment