Re: list of year form
On Monday, June 4, 2012, 11:04:58 PM, you wrote:
> Hi All,
> I want to create list of year select form.
> I know that i can generate the value using html.
> Is there a way to generate the value using forms API.
> For example, i want to generate select field that display year from 1970-2011.
> Thanks
What about using the 'SelectDateWidget' widget from
'django.forms.extras.widgets'? You could so something like:
You can pass a list of years to the constructor. Something like:
from django.forms.extras.widgets import SelectDateWidget
class MyForm(forms.Form):
...
date = forms.DateField(widget=SelectDateWidget(years=range(1970, datetime.today().year)))
...
Take a look at the source code of the widget. For example, some time
ago I created my own SelectDateWidget to override the 'none_value' it
places by default (---).
--
Oscar Mederos
omederos@gmail.com
--
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