[Answered ]-Djago time widget not showing up

1👍

You can try to fill the default values with the current time.

from datetime import datetime


class WorkOut(models.Model):
    move = (("1", "Tom"), ("2", "Sara"), ("3", "Emilia"),)
    date = models.DateField(auto_now_add=True, auto_now=False, blank=True)
    day = models.DateField(auto_now_add=True, auto_now=False, blank=True)
    start = models.TimeField(default=datetime.now, null=True)
    name = models.CharField(max_length=100, choices=move)
    weight = models.CharField(max_length=100, blank=True)
    rep = models.CharField(max_length=100, blank=True)
    pedal = models.CharField(max_length=100, blank=True)
    stretchtype = models.CharField(max_length=100, blank=True)
    end = models.TimeField(default=datetime.now,null=True)
    note = models.TextField(max_length=300, blank=True)

    def __str__(self):
        return self.name  

Update 22.10.2022
Made fields with time selection on bootstrap.
For this you need to install:

pip install django-bootstrap4
pip install django-bootstrap-datepicker-plus

In the WorkOutForm class in init set the styles for all fields.

forms.py

from bootstrap_datepicker_plus.widgets import TimePickerInput

class WorkOutForm(ModelForm):
    class Meta:
        model = WorkOut
        fields = "__all__"
        widgets = {
            "start": TimePickerInput(),
            "end": TimePickerInput(),

        }
    def __init__(self, *args, **kwargs):
        super(WorkOutForm, self).__init__(*args, **kwargs)
        for field in iter(self.fields):
            self.fields[field].widget.attrs.update({
                "class": "form-control"
            })

templates

{% load bootstrap4 %}
{% bootstrap_css %}
{% bootstrap_javascript jquery='full' %}
{{ form.media }}

<form action="" method="POST" style="width: 20%">
    {% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Submit">
</form>

enter image description here

Leave a comment