0

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!

J. Hesters
  • 13,117
  • 31
  • 133
  • 249

1 Answers1

1

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

Vaibhav Gupta
  • 650
  • 7
  • 15