Django AdminDateWidget apprearing as TextInput

Viewed 188

I don't understand how widgets work.

I tried this minimum example :

in my forms.py

    class PartialResetForm(forms.Form):
        date = forms.DateField(
            label="Starting date",
            widget=AdminDateWidget()
        )

in my admin/intermediary_reset_page.html

{% extends "admin/base_site.html" %}

<!--Loading necessary css and js -->
{{ form.media }}

{% block content %}
<form action="" method="post">{% csrf_token %}
    <!--  The code of the form with all input fields will be automatically generated by Django  -->
    {{ form }}
    <!--  Link the action name in hidden params -->
    <input type="hidden" name="action" value="custom_action" />
    <!--  Submit! Apply!  -->
    <input type="submit" name="apply" value="Submit" />
</form>
{% endblock %}

in my admin.py as the definition of an action

    def custom_action(self, request, queryset):    
        form = PartialResetForm()

        return render(request, "admin/intermediary_reset_page.html", {
            "items": queryset, "form": form
        })

For now I don't care about the queryset, it will be my next topic. With this simple example, I wanted to have a calendar in order to help pick a date, but only a TextInput appeared. I believe it is due to the fact that AdminDateWidget inheritates from TextInput.

My question is why isn't it appearing as a calendar ? I imported the media and declared my widget, I don't understand what else I'm supposed to do.

1 Answers

you should declare type

AdminDateWidget(attrs={'type': 'date'})

And it should be enough ;)

Related