[Fixed]-Django: select a instance of a parent model at ModelForm

0๐Ÿ‘

โœ…

Iโ€™ve just solved. By adding name="product", Iโ€™ve achieved it. Thank you for your cooperation!

  <select>
    {% for product in products %}
      <option value="{{ product.id }}">{{ product.name}}</option>
      <div class="error">{{ form.product.id.errors }}</div>
    {% endfor %}
  </select>

  <select name="product">
    {% for product in products %}
      <option value="{{ product.id }}">{{ product.name}}</option>
      <div class="error">{{ form.product.id.errors }}</div>
    {% endfor %}
  </select>
๐Ÿ‘คToshi

1๐Ÿ‘

You send data to server by submitting html form. See form example from step 4 of the tutorial โ€“ https://docs.djangoproject.com/en/1.10/intro/tutorial04/
See also http://www.w3schools.com/html/html_forms.asp for general description of html forms

Leave a comment