Nis,
Thanks for the reply. I tried your example and that does not work. Here is the
snippet of my code:
views.py
def displayresults(request, object_id):
result = Result.objects.get(pk=object_id)
startdatevalue = ''
starttimevalue = ''
startdatestr = '%s' % result.ExecutionStartDate
if startdatestr != 'None':
startdatevalue = "%04d-%02d-%02d" % (
result.ExecutionStartDate.year, result.ExecutionStartDate.month,
result.ExecutionStartDate.day)
starttimevalue = "%02d:%02d:%02d" % (
result.ExecutionStartDate.hour, result.ExecutionStartDate.minute,
result.ExecutionStartDate.second)
result_dict = {'TestName': result.TestName,
'TestVersion': result.TestVersion,
'ExecutionStartDate_date': startdatevalue,
'ExecutionStartDate_time': starttimevalue,
'SubmitDate': result.SubmitDate,
'ExecutionTime': result.ExecutionTime,
'Owner': result.Owner,
'Project': result.ProjectId,
'Phase': result.PhaseId,
'Testtype': result.TestTypeId,
'Station': result.StationId,
'UserIntervention': result.UserInterventionFlag,
}
form = DisplayResults(result_dict)
resultforms.py:
class DisplayResults(forms.Form):
TestName = forms.CharField()
TestVersion = forms.CharField()
ExecutionStartDate_date = forms.DateField()
ExecutionStartDate_time = forms.TimeField()
SubmitDate = forms.CharField()
ExecutionTime = forms.CharField()
Owner = forms.CharField()
Project = forms.CharField()
Phase = forms.CharField()
Testtype = forms.CharField()
status = forms.ChoiceField(required=False,choices
=(('choice1','Choice1'),('choice2','Choice 2')), initial = 'choice2' )
Here is the html output:
<tr><th><label for="id_status">Status:</label></th><td><select name="status" id=
"id_status">
<option value="choice1">Choice1</option>
<option value="choice2">Choice 2</option>
</select></td></tr>
Jeff
-------------- Original message --------------
From: Nis Jørgensen <[EMAIL PROTECTED]>
>
> [EMAIL PROTECTED] skrev:
> > I am still having problems setting the select widget to the 3rd value in
> > the
> drop down list.
> > Looking further it seems that the html does not have the
> > selected="selected"
> value in any of the items.
> > The documentation states that if use a bound form you will see that in the
> html.
>
> "initial" data are showed in an UNBOUND form. If the form is bound, it
> shows the data you bound it to. This is clearly stated in the
> documentation - I assume you mistyped here.
>
> > How would you go about getting the selected value in the html for a
> choicefield. I tried the initial parameter in the choicefield and that does
> not
> change which value is selected. It always happens to be the first in the
> list.
> >
> > Any help would greatly appreciated.
>
> For an unbound form, it works for me:
>
> """
> $ cat forms.py
> from django import newforms as forms
>
> class SearchForm (forms.Form):
> campaign = forms.ChoiceField(required=False,choices
> =(('choice1','Choice1'),('choice2','Choice 2')), initial = 'choice2' )
> sf = SearchForm()
> print sf
>
> $ python forms.py
> Campaign:> name="campaign" id="id_campaign"> > Choice1 > Choice 2 >
> """
>
> Can you please
>
> a) Confirm that the above works for you
> b) Post a self-contained example which shows your problem
>
> Nis
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---