how to use choicefield in django

25 views Asked by At

i have table in db in which i stores countries and i dynamically pass those countries in template and and in forms.pt i have a ChoiceField(widget=forms.Select,required=True) like this but i didnot get the value from this filed but when i chane it into CharField i get the value.

              <div class="form-group col-md-4 select-border">
                <label>Country</label>
                <select class="form-control basic-select" name="country">
                    {% for country in countries %}
                        <option value="{{ country.value }}">{{ country.value }}</option>
                    {% endfor %}
                </select>
              </div>

form.py country = forms.ChoiceField(widget=forms.Select,required=True)

views.py users_meta.candidate_country = ProfileForm.cleaned_data['country']

0

There are 0 answers