D
D
Dzhemchik2020-04-24 20:47:07
Django
Dzhemchik, 2020-04-24 20:47:07

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>


#model
class Category(models.Model):
    name = models.CharField('Категория', max_length=100, db_index=True)
    slug = models.SlugField(max_length=100, db_index=True,
                            unique=True)

Tell me what I'm doing wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question