4

This is what am trying to achieve

enter image description here

Forms.py
class MyForm(forms.ModelForm):

     Recorded_datetime = forms.DateTimeField()

I want the field to have a seperate date and time input like in the case of pub_date field in the famous poll app. What should I call in the template to achieve that? I have tried SplitDateTimeWidget but still cant achieve that. What Am getting is enter image description here

Help please. Thanks.

2
  • What doesn't work about the SplitDateTimeWidget?
    – jproffitt
    Commented Sep 27, 2013 at 0:52
  • 1
    @jproffitt I dont know Its usage, I did Recorded_datetime = forms.SplitDateTimeWidget() and I did't exactly know how to call it in template.
    – Alexxio
    Commented Sep 27, 2013 at 1:24

1 Answer 1

4

You can use a SplitDateTimeWidget. This is how you change the widget:

Recorded_datetime = forms.DateTimeField(widget=forms.SplitDateTimeWidget())
3
  • 2
    Its splitting them pretty well but how do I add the date and time pickers?
    – Alexxio
    Commented Sep 28, 2013 at 2:21
  • 2
    I got it working, What I did was to subclass class AdminSplitDateTime then override format_output method and put bootstrap date and time pickers there.
    – Alexxio
    Commented Oct 2, 2013 at 11:08
  • @alexxio whats code example?
    – LSM
    Commented Mar 3, 2022 at 3:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.