Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django python: Using DateInput --Required argument 'year' (pos 1) not found

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 %}
like image 540
user1807271 Avatar asked Jul 10 '15 16:07

user1807271


1 Answers

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().

like image 145
Adrian Ghiuta Avatar answered Oct 30 '22 20:10

Adrian Ghiuta