Django date time picker

42 views
Skip to first unread message

Thomas Mutavi

unread,
May 29, 2023, 1:15:23 PM5/29/23
to Django users
Hello, how  can i implement a form with several date fields which have date and time picker in django?

Larry Martell

unread,
May 29, 2023, 1:18:58 PM5/29/23
to django...@googlegroups.com
On Mon, May 29, 2023 at 1:14 PM Thomas Mutavi <mathias...@gmail.com> wrote:
>
> Hello, how can i implement a form with several date fields which have date and time picker in django?

You can use the jQuery UI datetimepicker.

Bhuvnesh Sharma

unread,
May 29, 2023, 1:20:46 PM5/29/23
to django...@googlegroups.com
You can also use https://github.com/monim67/django-bootstrap-datepicker-plus

It is really good and easy to integrate.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACwCsY72xpH90NiaJMQCWeziz%3DqPZcnDPZewBVt3BHMSjVcowQ%40mail.gmail.com.

sum abiut

unread,
May 29, 2023, 5:36:30 PM5/29/23
to django...@googlegroups.com
You can use model forms and do something like this:
1) create your model. for instance
class DatePickerModel(models.Model):
    start_date = models.DateTimeField()
    end_date = models.DateTimeField()
2) create your form
  # setup date picker start
class DateInput(forms.DateInput):
    input_type = 'date'


class DatePickerForm(forms.ModelForm):
    class Meta:
        model = DatePickerModel
        widgets = {'date': forms.DateInput(attrs={'class': 'datepicker'})}
        fields = ['start_date', 'end_date']
        widgets = {
            'start_date': DateInput(), 'end_date': DateInput()
        }
        error_messages = {
            'start_date': {'required': ''},
            'end_date': {'required': ''}
        }

3) in your html 
                 <form method="post">
                        {% csrf_token %}
                        {{ form.as_p }}
                        <button type="submit" class="btn btn-primary">submit</button>
                    </form>

Sebastian Jung

unread,
May 30, 2023, 1:40:18 AM5/30/23
to django...@googlegroups.com
Solution from Sun abiut is only beginning. Now you must insert in html code that you import a javascript datetime picker and activate it on all fields with class datepicker

ivan harold

unread,
Aug 9, 2023, 11:10:18 AM8/9/23
to Django users
Reply all
Reply to author
Forward
0 new messages