0

I've added the FloppyForms SplitDateTimeWidget to my datetime fields and if there is a value already stored the time is correctly set as expected in the forms, but the date just comes out as dd/mm/yyyy.

What am I missing to get the form to correctly set the date value?

# forms.py
from django import forms

from generic.forms.widgets.floppyforms import SplitDateTimeWidget

from consoles.models import Event


class EventForm(forms.ModelForm):

    class Meta:
        model = Event
        exclude = ('slug',)
        widgets = {
            'qualifying_date': SplitDateTimeWidget(date_format='%d/%m/%Y'),
        }

The HTML generated has the correct value attribute, but the widget just shows 'dd/mm/yyyy'

<input type="date" name="start_0" value="21/08/2014" id="id_start_0">
<input type="time" name="start_1" value="10:00:00" id="id_start_1">
markwalker_
  • 12,078
  • 7
  • 62
  • 99
  • What is the format of the date as returned by the queryset? – Burhan Khalid Aug 21 '14 at 07:54
  • @BurhanKhalid how do you get the queryset for a datetime field or splitdatetimefield? I've done that for ModelChoiceField but not aware you can provide it for a date/time field. – markwalker_ Aug 21 '14 at 15:32

1 Answers1

0

Based on this question django: SplitDateTimeWidget ignores date_format, you also have to specify input_date_format

class EventForm(forms.ModelForm):

  class Meta:
    model = Event
    exclude = ('slug',)
    widgets = {
        'qualifying_date': SplitDateTimeWidget(date_format='%d/%m/%Y'),
    }
    qualifying_date = SplitDateTimeField(input_date_formats=['%d/%m/%Y'],
                           input_time_formats=['%H:%M'])
Community
  • 1
  • 1
klasske
  • 2,164
  • 1
  • 24
  • 31