Django:如何将来自forms.py的表单中的选项标记为选中

时间:2019-11-24 05:01:53

标签: django django-forms

这是我的表格。py:

from django import forms
from users.models import EnglishInterest, UserPlans

class CLSelectionForm(forms.Form):

    plan_choices = UserPlans().get_plan_choices_active()
    englishInterest_choices = EnglishInterest().get_english_interest_active()

    useremail = forms.EmailField(widget=forms.HiddenInput(attrs={
        'type': 'email'}))
    coupon = forms.CharField(widget=forms.HiddenInput(attrs={
        'type': 'email'}))

    plans = forms.CharField(label='Plan Choice',
                        widget=forms.Select(choices=plan_choices, attrs={'id': 'plan_choice', 
              'class': 'fs-anim-lower fs-select-box', 'name': 'plan_choice'}))
    englishInterest = forms.CharField(
        label='English Interest', widget=forms.Select(choices=englishInterest_choices, attrs={'id': 
         'english_choice', 'class': 'fs-anim-lower fs-select-box', 'name': 'english_choice'}))

    submitButton = forms.CharField(widget=forms.TextInput(
        attrs={'type': 'submit', 'name': 'submit', 'id': 'fs-submit-button', 'class': 'fs-submit', 
         'value': 'Submit'}))

    class Meta:
        fields = ['useremail', 'coupon', 'plans', 'englishInterest']

我该如何使用包含选定属性的选项来呈现计划和englishInterest表单元素?

0 个答案:

没有答案