Date_Format = (
('0', ' dd / mm / yyyy'),
('1', 'mm / dd / yyyy'),
)
Time_Format = (
('0', ' 12 hour AM / PM '),
('1', ' 24 hour '),
)
class SettingsForm(forms.ModelForm):
date_format = forms.ChoiceField(widget=forms.RadioSelect(), choices=Date_Format)
time_format = forms.ChoiceField(widget=forms.RadioSelect(), choices=Time_Format)
Update:
{% for radio in SettingsForm.date_format %}
{{ radio.choice_label }}
<div class="select">{{ radio.tag }}</div>
{% endfor %}
The above form is rendering the radio buttons in a unordered list, but I want to be with out unordered list. How can I perform this?
You could create a custom renderer:
from django import forms
from django.forms.widgets import RadioFieldRenderer
from django.shortcuts import render
from django.utils.html import format_html_join
from django.utils.encoding import force_text
class RadioFieldWithoutULRenderer(RadioFieldRenderer):
def render(self):
return format_html_join(
'\n',
'<li>{0}</li>',
[(force_text(w), ) for w in self],
)
CHOICES = (
('0', ' 12 hour AM / PM '),
('1', ' 24 hour '),
)
class MyForm(forms.Form):
somefield = forms.ChoiceField(
widget=forms.RadioSelect(renderer=RadioFieldWithoutULRenderer),
choices=CHOICES)
def myview(request):
return render(request, 'form.html', {'form': MyForm()})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With