views:

1124

answers:

2

Hello,

I have a Form with a DateField. The formatted date look like this:

2009-10-03

How can i Format that? I want it look like this:

03.10.2009

I found a widget which renders it like this, but validation doesnt allow the values i enter then...

Bye falstaff

+2  A: 

To display initial field value properly formatted, use DateInput widget. To customize validation, use input_formats keyword argument of DateField.

PiotrLegnica
Thanks this worked... It looks like this now:my_date = forms.DateField(initial=date.today(), widget=forms.DateInput(format = '%d.%m.%Y'), input_formats=('%d.%m.%Y',))
falstaff
Note: I believe this works only with Django 1.1 and above. I'm using 1.0.
dfrankow
A: 

Subclass custom field like this:

class CustomDateField(forms.DateField):
  def __init__(self, *args, **kwargs):
    kwargs.setdefault('input_formats', ("%d.%m.%Y",))
    super(CustomDateField, self).__init__(*args, **kwargs)
sorki