I am building a dashboard which will have some information about users. I am trying to set value to select tag using Django but the value never get assigned. Here is my code.
My model look something like this
class User(models.Model):
first_name
last_name
reg_status
I need to fill in the template with the reg_status
. The reg_status
can contain three options, they are as mentioned below:
mailed
register
not register
The value of reg_status
is dynamic. For example, if I pass in reg_status = mailed
from my view, I need the <option value='mailed'>
to be selected. However, if I pass in the reg_status = register
from my view, I need the <option value='register'>
to be selected.
Here is how I am trying to render the content in the template:
{% for u in user %}
<input type='text' value={{u.first_name}}/>
<input type='text' value={{u.last_name}}/>
<select value={{u.reg_status}>
<option value='mailed'>mailed</option>
<option value='register'>register</option>
<option value='not register'>not register</option>
</select>
{% endfor %}
The output give 'mailed' as selected for all instance even if the value is set to 'registered' or 'not registered'.