[Fixed]-Django: Models values as global variables

0👍

Restart your wsgi server (Nginx). That should take care of the problem.

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>

Leave a comment