﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22208	Weird SplitDateTime widget Behaviour regarding initial data between bound & unbound forms	Ramezashraf@…	nobody	"I need to send initial date & time to a SplitDateTime widget in a model form

an example:

models.py
{{{
class Event(models.Model):
    event_name = models.CharField(max_length = 250)
    start_date = models.DateTimeField(db_index = True, )
    end_date = models.DateTimeField(db_index = True)
}}}

forms.py
{{{
class add_event (forms.ModelForm):
    start_date = forms.SplitDateTimeField(input_time_formats=['%I:%M %p'], widget=forms.SplitDateTimeWidget(date_format='%Y-%m-%d', time_format='%I:%M %p'))
    end_date = forms.SplitDateTimeField(input_time_formats=['%I:%M %p'], widget=forms.SplitDateTimeWidget(date_format='%Y-%m-%d', time_format='%I:%M %p'))
}}}
views.py

{{{
import datetime as dt
def myview(request):
    data={}
    data['event_name'] = 'Awesome Event'
    data['start_date'] = dt.datetime.now

    #Now i send the 'initial' data to form , I Tried the following:
    form = add_event(initial=data) #1st: Works fine,everything is populated as expected, But i get an unbound form , with no validation
    form = add_event(data)  # 2nd: event_name field is populated right but the SplitDatetime widget is not, (come out as an Empty widget)
    form = add_event(data=data) #3rd: Same as previous , Event_name field is populated right but the SplitDatetime widget is not

}}}

However , removing the splitDatetimeWidget from the add_event fields definition , would make the 3rd solution working & everything is populated fine
But results of a combined text field with both the date & time.

Searched over the internet , tried every solution , none seem to work , although i know there is some way of doing it , or else , CBV updating an event would contains empty SplitDateTime value as well. but i can't find the solution or deeper diagnose the problem.

What is missing here?
Perhaps this can be added to documentation. (If it's not already there and i didn't see it)


Thank you so much !!

Best regards;"	Uncategorized	closed	Forms	1.6	Normal	invalid	SplitDateTimeWidget , ModelForms		Unreviewed	0	0	0	0	1	0
