Saturday, July 7, 2012

database values in a select form.

I have a table, Choice, that is used to build common lists. For
instance, there might be a list "Employment_Status" with values
"Full-Time" and "Part-Time"

I want to use those values in various forms, so in the appropriate
models.py I have:

def _get_list_choices(list):
choices = Choice.on_site.filter(category =
list).values_list('choice', flat=True).order_by('sort_order')
return tuple(choices)


and then I'd use it like this:

class PersonForm(ModelForm):
household = forms.CharField(
widget=forms.HiddenInput())
employment_types = _get_list_choices('Employment_Status')
employment_status = ChoiceField(widget=forms.Select, choices =
zip(employment_types,employment_types))


What I'm noticing is that (in dev mode) the choice list for
'employment_status' doesn't update unless I trigger a change, either
to the forms.py or restart the dev server.

I'm wondering if there's a better place to handle this.

Thanks.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate