J. Hesters
J. Hesters

Reputation: 14766

Django: Timefield widget not showing in template

TLDR: how do I get my timefield to show in the template?

I customized my ModelForm in the class meta. For some reason, only the label change is shown, not the widget change. Here is my code:

class MenuCreateForm(forms.ModelForm):
    class Meta:
        model = Menu
        fields = (
            'name',
            'monday',
            'availability_begin_mon',
            'availability_end_mon',
        labels = {
            'availability_begin_mon': ('Begin Montag'),
            'availability_end_mon': ('Ende Montag'),
        widgets = {
            'availability_begin_mon': forms.TimeInput(format='%H:%M'),
            'availability_end_mon': forms.TimeInput(format='%H:%M'),

And here is the template I used:

<form method="POST"> {% csrf_token %}
        {{ form.as_p }}
        <button class="btn btn-primary" type='submit'>Änderungen speichern</button>
</form>

Does anyone have an idea? Thank you very much!

Upvotes: 0

Views: 2143

Answers (1)

Vaibhav Gupta
Vaibhav Gupta

Reputation: 680

By default, django forms does not show Date/Time widget in custom forms. If you want that, there's a hack-ish way to do it. please refer to the following discussion Using Django time/date widgets in custom form

Upvotes: 1

Related Questions