I have a form on Django which is filled with data when viewing a specific instance of a model.
(I´m using the format : dd/mm/yyyy, I need the days first because it´s a foreign project)
I wanted to use the type='date'
attribute to get a calendar widget so I added this line on top of my forms.py
forms.DateInput.input_type="date"
forms.TimeInput.input_type="time"
I managed to get the widgets as I wanted, but now for some reason, the date field is no being filled with the data coming in the request. As soon as I remove the above lines, I get the data once again.
this is my complete forms.py:
from six.moves.builtins import object
from django import forms
from django.utils.translation import ugettext_lazy as _
from schedule.models import Event, Occurrence
forms.DateInput.input_type="date"
forms.TimeInput.input_type="time"
class SpanForm(forms.ModelForm):
start = forms.DateTimeField(label=_("Incio"),
widget=forms.SplitDateTimeWidget)
end = forms.DateTimeField(label=_("Fin"),
widget=forms.SplitDateTimeWidget,
help_text=_(u"The end time must be later than start time."))
def clean(self):
if 'end' in self.cleaned_data and 'start' in self.cleaned_data:
if self.cleaned_data['end'] <= self.cleaned_data['start']:
raise forms.ValidationError(_(u"The end time must be later than start time."))
return self.cleaned_data
class EventForm(SpanForm):
def __init__(self, *args, **kwargs):
super(EventForm, self).__init__(*args, **kwargs)
end_recurring_period = forms.DateTimeField(label=_(u"Periodo de Recurrencia"),
help_text=_(u"Esta fecha se ignora si es un evento de una unica ocurrencia"),
required=False)
class Meta(object):
model = Event
exclude = ('creator', 'created_on', 'calendar','end_recurring_period')
class OccurrenceForm(SpanForm):
class Meta(object):
model = Occurrence
exclude = ('original_start', 'original_end', 'event', 'cancelled','end_recurring_period')
Can anyone help me get the date widget filled with data automatically?