On 13-8-2012 14:47, houmie wrote:
> Thanks Melvyn,
>
> I have tried this:
>
> def contact_date_callback(self, field, **kwargs) :
> return field.contact_date(localize=True, **kwargs)
>
> But the date still shows as 2012-08-13
>
> note, that Aptana Studio 3.0 complained that I put `self` first.
>
> Nonetheless neither version works.
It works, but it's not visible:
>>> from one.models import Person, localize_field
>>> from django.forms.models import modelform_factory
>>> FormClass = modelform_factory(Person, formfield_callback=localize_field)
>>> form = FormClass()
>>> form.fields['registered'].localize
True
>>> from django.utils.translation import activate
>>> activate('en-us')
>>> print form
...
<input type="text" name="registered" value="2012-08-13"
id="id_registered" />
...
>>> activate('nl_NL')
>>> print form
...
<input type="text" name="registered" value="13-08-2012"
id="id_registered" />
...
The reason is in django/conf/locale/en/formats.py. Localize uses the
first *_INPUT format available, which happens to be:
DATE_INPUT_FORMATS = (
'%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', # '2006-10-25', '10/25/2006',
'10/25/06'
So if you want a different input format, you'll need to override this as
described at:
<https://docs.djangoproject.com/en/1.4/topics/i18n/formatting/#creating-custom-format-files>
--
Melvyn Sopacua
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
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.