I have something like this in form :
class EventForm(ModelForm):
reg_due_date = forms.DateTimeField(input_formats=('%d/%m/%Y %H:%M',), widget=forms.TextInput(attrs={ 'class': 'datePicker','readonly':'true'}))
and
class Event(models.Model):
reg_due_date = models.DateTimeField()
Everything is ok, when I use jQuery DateTimePicker I have correct datetime format in the input field. But when I try to edit the form via this part of code I see seconds appearing and it is totally unacceptable. Where it comes from?
def editEventInfo(request,event_id):
if request.method == 'GET':
if event_id:
event = Event.objects.get(pk=event_id)
form = EventForm(instance=event) # An unbound form
else:
form = EventForm() # An unbound form
return render_to_response('events/editEvent.html', {
'form': form,
},context_instance=RequestContext(request))
input_formatsis the list of formats the form field will use to parse the input string into a date, what’s printed is driven by the format localization.you either need to activate
USE_L10N = Trueor overrideDATETIME_FORMATSee https://docs.djangoproject.com/en/1.4/topics/i18n/formatting/ and https://docs.djangoproject.com/en/1.4/ref/settings/#datetime-format