How to Combine WTForms Date Field with Two Dropdown Menus for Start and End Time Selection in Python?

38 Views Asked by At

Using WTForms for Python, I would like to combine the Date field (that shows a calendar) with two dropdown menus where start time and end time can be selected, ending up with the same content as if a DateTime field was used.

For a user it can be a better way to select rather than to write in the DateTime field.

I need to find out how to combine the input values that come from using the dropbox and the Date field:

startdate = DateField('Start date    ', format='%Y-%m-%d', default=today, validators=(validators.DataRequired(),))

enddate = DateField('End date    ', format='%Y-%m-%d', default=today, validators=(validators.DataRequired(),))

# Drop down menus   
 starttime_selection = SelectField('Start time', [DataRequired()], choices=STARTTIME_SELECTION)
 endtime_selection = SelectField('End time', [DataRequired()], choices=ENDTIME_SELECTION)

I would like to end up with this format '%Y-%m-%d %H:%M:%S', which I can use in an SQL statement (where seconds should always be 00):

start_datetime = DateTimeField('Dato og starttidspunkt', format='%Y-%m-%d %H:%M:%S',
                                         validators=(validators.DataRequired(),)
    
end_datetime = DateTimeField('Dato og sluttidspunkt', format='%Y-%m-%d %H:%M:%S',
                                       validators=(validators.DataRequired(),)

0

There are 0 best solutions below