Sunday, April 27, 2014

change the default value choicefield

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?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e690d4d4-03fb-43e6-b908-886ed52d295e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment