<div id="div_id_time_field" class="mb-3">
<label for="id_time_field" class="block text-gray-700 text-sm font-bold mb-2">
Time field<span class="asteriskField">*</span>
</label>
<div>
<input
data-controller="flatpickr"
data-flatpickr-enable-time="true"
data-flatpickr-no-calendar="true"
type="text"
name="time_field"
class="block py-2 px-4 w-full leading-normal text-gray-700 bg-white rounded-lg border border-gray-300 appearance-none focus:outline-none textinput"
value="02:05:28"
data-flatpickr-enable-seconds="false" class="customtimewidget " required id="id_time_field"
>
</div>
</div>
def pick_time(self, **kwargs):
class TestForm(forms.Form):
time_field = forms.TimeField(
initial=timezone.now,
widget=CustomTimeWidget(
attrs={
"data-flatpickr-enable-seconds": "false",
},
),
)
form = TestForm()
template = Template(
"""
{% load crispy_forms_filters %}
{{ form.time_field|as_crispy_field }}
""",
)
return template.render(Context({"form": form}))