I'm trying to use DateInput, but I get the following error
Required argument 'year' (pos 1) not found here {{ form.incident_date_time_reported|add_class:"form-control"}} (line 52)
forms.py
from django import forms
import datetime
from functools import partial
DateInput = partial(forms.DateInput, {'class': 'datepicker'})
class IncidentForm(forms.Form):
    incident_date_time_reported = forms.DateField(initial=datetime.date, required=False, widget=forms.DateInput)
    def search(self):
        # cleaning the data
        incident_date_time_reported = self.cleaned_data.get('incident_date_time_reported')
        query = Incident.objects.all()
        if incident_date_time_reported is not None:
            query = query.filter(incident_date_time_reported=incident_date_time_reported)
        return(query)
index.html
{% extends "base.html" %}
{% load widget_tweaks %}
{% block content %}
<div class="container-fluid">
    <!-----INPUT FORM------------------->
    <form action="{% url 'incidents:index' %}" method="GET">
        <div class="row">                       
            <div class="form-group col-md-3">
                <label>Date Incident Reported</label><br>
                {{ form.incident_date_time_reported|add_class:"form-control"}}
                {{ form.incident_date_time_reported.errors }}
            </div>
            <div class="form-group col-md-3">
                <label>------</label>
                <button type="submit" class="btn btn-primary btn-block">Search</button>
            </div>
        </div>
    </form>
</div><!-----END OF BOOTSTAP CONTAINER FLUID----->
{% endblock %}
                datetime.date is incorrectly used. It's a function with all the arguments required.
If you are attempting to initially populate with the current day, you should use datetime.date.today().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With