Hi,
I am trying to have a drop down menu for a field in my form but seems like its not working as required.
This is my form: forms.py
eval_states = [
('ACTIVE',EvalState.objects.filter(name='ACTIVE')),
('INACTIVE',EvalState.objects.filter(name='INACTIVE')),
('DELETE',EvalState.objects.filter(name='DELETE')),
]
class EvalForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(EvalForm, self).__init__(*args, **kwargs)
self.fields['name'].queryset = EvalState.objects.filter(
Q(name = 'ACTIVE') | Q(name = 'INACTIVE') | Q(name = 'DELETE'))
class Meta:
model = EvalState
fields = ('name',)
my html : abc.html
<form name="eval_form" method="post" action="#">{% csrf_token %}
<table class="pairs">
<tr>
<th>Eval State:</th>
<td>
{{
eval_form.name }}
<input type="submit" value="Save">
</td>
</tr>
</table>
</form>
view.py
eval_form = None
eval_form = atlas_forms.EvalForm(request.POST, EvalState)
if eval_form.is_valid():
print eval_form.errors
eval_form.save()
else:
print eval_form.errors
What am i missing?
Basically requirement is that, i would need a drop down in the HTML and whenever the Value is set and saved, I want it to be updated in the DB.
But i am not able to get through the first step of getting the options in the HTML.
Any Help on this would be great.
Thanks
cheers
Arun.