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!

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! That helped a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.