change the default value choicefield

已查看 8 次
跳至第一个未读帖子

Helton Alves

未读,
2014年4月27日 10:15:322014/4/27
收件人 django...@googlegroups.com
Hi guys, I'm new here on the list.
I have a question.
yesterday I needed create a form with some fields and one the field was using select with choicefield.
I needed edit in label default of select.

was as follows:
<option>------------</option>

I wanted like this:
<option>Your state</option>

I done like this:

get the tuple with all states using the localflavor.br.br_states
I have all states in STATE_CHOICES

add on top of tupla like this:
STATE_CHOICES = ((None, u'Your state'),) + STATE_CHOICES

and then like this:
state = forms.ChoiceField(choices=STATE_CHOICES, required=False)

so I got what I wanted but but I think this resolution was not the best.
could someone show me other resolution more elegant?

回复全部
回复作者
转发
0 个新帖子