Answer the question
In order to leave comments, you need to log in
How to save the selected select element?
Hello!
After submitting the form, it is not possible to save the select field selected by the user.
<div class="form-group col-md-2 col-lg-2">
<label for="category">Категория</label>
<select id="category" class="custom-select" name="category">
{% for option in categories %}
<option value="{{option.name}}" {% if option == option.name %}selected{% endif %}>
{{ option.name|capfirst }}
</option>
{% endfor %}
</select>
</div>
class Category(models.Model):
name = models.CharField('Категория', max_length=100, db_index=True)
slug = models.SlugField(max_length=100, db_index=True,
unique=True)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question