Created
February 10, 2014 16:17
-
-
Save ErDmKo/8918792 to your computer and use it in GitHub Desktop.
Select, radio and checkbox customization django
This file contains hidden or 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
#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'}) | |
} |
This file contains hidden or 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
{% with choice_list=form.education %} | |
{% include 'widgets/custom_select.html' %} | |
{% endwith %} |
This file contains hidden or 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
{% 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 %} |
This file contains hidden or 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
<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