birth date in a model form

1,521 views
Skip to first unread message

DragonSlayre

unread,
Jan 5, 2009, 5:00:01 PM1/5/09
to Django users
Hi,

I've got a ModelForm, and the model for it contains a birth date field
(as a DateField):

class FiremanForm(ModelForm):
class Meta:
model = Fireman

Currently a single text box is rendered to enter the date, but I'd
like to have a drop down list for day, month, year.

I'm guessing that lots of people have come across this, and I was
wondering what the best way is to get these drop down lists on the
page ?

Are there any widgets that I don't know about that I should be using,
or should I be creating my own, or should I be breaking my Fireman's
birthdate up into day, month year..... or something else?

Brot

unread,
Jan 5, 2009, 5:29:22 PM1/5/09
to Django users
Hello,

I have the same issue in my app and there is a widget. You can find it
here:
http://code.djangoproject.com/browser/django/trunk/django/forms/extras/widgets.py

But for me this widget misses a few features and there are open
tickets with patches, but they are not in trunk yet :-(
http://code.djangoproject.com/ticket/9124
http://code.djangoproject.com/ticket/6231

I am working with the latest patch from #6231 and so the widget is now
useful for me. But I hope that this patch find it's way into django
trunk!

~Bernd

DragonSlayre

unread,
Jan 5, 2009, 6:11:04 PM1/5/09
to Django users
I've tried using it, but I'm still quite new to django - I put it into
my model file for now, and made my model form looks like this:

class FiremanForm(ModelForm):
birth_date = models.DateField(widget=SelectDateWidget())

But I get an error "got an unexpected keyword argument 'widget' "
From this I gather that I must be writing the wrong thing, but I'm not
sure what I should be writing?


Thanks a lot

On Jan 6, 11:29 am, Brot <schla...@gmail.com> wrote:
> Hello,
>
> I have the same issue in my app and there is a widget. You can find it
> here:http://code.djangoproject.com/browser/django/trunk/django/forms/extra...
>
> But for me this widget misses a few features and there are open
> tickets with patches, but they are not in trunk yet :-(http://code.djangoproject.com/ticket/9124http://code.djangoproject.com/ticket/6231

Brot

unread,
Jan 5, 2009, 6:53:09 PM1/5/09
to Django users
from django import forms
from django.forms.extras import widgets

class FiremanForm(forms.ModelForm):
birth_date = forms.DateField(widget=widgets.SelectDateWidget())

On Jan 6, 12:11 am, DragonSlayre <LSSay...@gmail.com> wrote:
> I've tried using it, but I'm still quite new to django - I put it into
> my model file for now, and made my model form looks like this:
>
> class FiremanForm(ModelForm):
>     birth_date = models.DateField(widget=SelectDateWidget())
>
> But I get an error "got an unexpected keyword argument 'widget' "
> From this I gather that I must be writing the wrong thing, but I'm not
> sure what I should be writing?
>
> Thanks a lot
>
> On Jan 6, 11:29 am, Brot <schla...@gmail.com> wrote:
>
> > Hello,
>
> > I have the same issue in my app and there is a widget. You can find it
> > here:http://code.djangoproject.com/browser/django/trunk/django/forms/extra...
>
> > But for me this widget misses a few features and there are open
> > tickets with patches, but they are not in trunk yet :-(http://code.djangoproject.com/ticket/9124http://code.djangoproject.co...

DragonSlayre

unread,
Jan 5, 2009, 7:07:02 PM1/5/09
to Django users
Oh, cool thanks :)

I never went into the code part of djangoproject before, always just
the documentation. That's great, thanks.
Reply all
Reply to author
Forward
0 new messages