1👍
Instead of doing that, you can use a ModelChoiceField
.
class MyForm(forms.Form):
choice = forms.ModelChoiceField(queryset=MyModel.objects.all())
...
This would yield the below in the template:
<select id="id_field" name="field">
<option value="obj1.id">Object1</option>
<option value="obj2.id">Object2</option>
...
</select>
- Extra long loading time on Angular/django app
- Access to user data from profile in admin.py
- Issue with saving checkbox value from form
- Django debug: how to know which template is in use for a specific URL?
Source:stackexchange.com