'__init__() got an unexpected keyword argument 'widget'

I'm trying to run web app page which uses the below form;

class InputParametersForm(ModelForm):

    sqlConnection = SQLSeverConnection(
        'MSSQLServerDataSource',
        'default_user',
        'password123!!',
        'HD'
    )
    tableChoices = sqlConnection.getTableNames()
    TableName = forms.Select(
        widget=forms.Select(attrs={'class': 'selector'})
    )
    ColumnName = forms.Select(
        widget=forms.Select(attrs={'class': 'selector'})
    )
    StartDateTime = forms.DateField(
        widget=SelectDateWidget(
            empty_label=("Choose Year", "Choose Month", "Choose Day")
        )
    )
    EndDateTime = forms.DateField(
        widget=SelectDateWidget(
            empty_label=("Choose Year", "Choose Month", "Choose Day")
        )
    )

    class Meta:
        model = SelectionHistory
        fields = ("TableName", "ColumnName", "StartDateTime", "EndDateTime")

When I run manage.py runserver and go to the local URL I'm getting a 500 page with the error __init__() got an unexpected keyword argument 'widget' where I've tried to use the widget.

This is probably some basic error I'm making but if somebody could point me in the right direction it'd be a big help - preferably with some code.



Solution 1:[1]

Another possibility when receiving this error message is that Django has different types of fields when dealing with db models and form models. Make sure that your includes are in the correct order; include forms AFTER models. If you do something along the lines of:

from models import *
from django.forms import *

This will force the Form's field objects to be used instead of the Model's field objects which DO have the widget keyword.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Fydo