I can't save data of <select> in html

Viewed 30

I have django application with form.

in model

LIVING_COUNTRIES = [
    ('AFGANISTAN', 'Afganistan'),
    ('ALBANIA', 'Albania'),
    ('ALGERIA', 'Algeria'),
    ('ANGORRA', 'Andorra')]
class Employee(models.Model):
country_living      =               models.CharField(max_length=50, choices=LIVING_COUNTRIES, default=FRESHMAN, blank=True, null=True)

in html

<select name="country" id="id_category" data="{{ data.country }}">
   {% for each in living_countries_list %}
        <option value="{{ each.0 }}" class="living_countries">{{ each.1 }}</option>
   {% endfor %}
</select>

in view

context['has_error'] = True
if context['has_error']:
    employees = models.Employee.objects.all()
    living_countries_list = LIVING_COUNTRIES
        return render(request, 'authentication/employee_register.html', context)

So I have form rendered in get() method of class-based view. When I click submit post method checks for errors. If there are any context['has_error'] is set to true. For simplycity I've written it down anyway. And if it is true we render form again. I want to have previous choice of user still displayed in html. I've done it on other inputs by `data="{{ data.field }}". How would I do that here?

0 Answers
Related