Отказ от выбора RadioSelect в Django ModelForm - PullRequest
1 голос
/ 24 июня 2019

У меня есть список вариантов. Я хочу получить значение по одному в HTML

forms.py

class ProfileForm(ModelForm):

class Meta:
    model = UserInfor
    fields = [ 'gender']
    widgets = {
        'gender': forms.RadioSelect(choices=GENDERS),
    }
    labels = {   
        'gender': "Gender",
    }

view.py

def profile(request):
user_info = ProfileForm()
return render(request, 'pages/test.html', {'user_info': user_info)

test.html

{% for choice in genders %}
     <label class="radio-inline" class="radio-inline"><input type="radio" value="???">{{ ??? }}</label>
{% endfor %}

1 Ответ

0 голосов
/ 24 июня 2019
{% for g_value, g_label in user_info.fields.gender.choices %}
    <label class="radio-inline" class="radio-inline"><input type="radio" value="{{ g_value }}">{{ g_label }}</label>
{% endfor %}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...