Hi,

I have a form with a TimeField and I'd like it to only accept values
in the form hh:mm, as opposed to hh:mm:ss.

The form is a ModelForm and I've overridden the 'time' field with a
TimeField where I've specified the input_formats as ['%H:%M']. This
works fine when entering value for a new instance of the model, but
when I edit an existing instance, the value that I entered as '12:30'
is rendered as '12:30:00' and so the instance fails to save.

Without much hope of success (and that proved wildly optimistic), I
tried changing the rendering of the form as follows:
 {% if field.label == "Time" %}
     {{ field | time:"H:i" }}
 {% else %}
    {{ field }}
 {%endif%}
But that didn't work even a little bit.

Do I need to subclass TimeField? Is there a method that controls the
"output_formats"?
Or maybe that's not the way to do it. Could anyone offer any advice?

Thanks in advance,

Brian

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to