On 3/14/07, Grupo Django <[EMAIL PROTECTED]> wrote:
>
> Hello, I have noticed that the field DateField in the newforms library
> doesn't validate all right when introducing data.
> I have this code:
>
> FormClass = forms.models.form_for_model(Model)
> form = FormClass(data)
> data = request.POST.copy()
> data['author'] = request.user
> formulario = FormClass(data)
>
> if form.is_valid():
>       form.save()
>
> And I get a validation error, meanwhile, when I validate using the
> shell with the following code, it's ok:
> >>> f2 = forms.DateField(input_formats=['%d/%m/%Y'])
> >>> f2.clean('25/10/2006')
> datetime.date(2006, 10, 25)
>
> What's wrong in the first case?

When you use form_for_model, the deafult import_formats argument that
gets used does not include '%d/%m/%Y'. It is expecting '%m/%d/%Y'
among other things.

The most straightforward solution would be to create a custom form
class instead of using form_for_model. There are a couple of other
options, but they're a little tricky if you aren't familiar with
Django's internals. Look at the docsting and code for form_for_model
for clues on the other 2 options and feel free to ask questions if it
doesn't make sense.

Joseph

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to