Reputation: 145
I'm trying to create a custom form/view in Calendarium and i keep getting an error
AttributeError: 'module' object has no attribute 'SelectDateWidget'
CreateEvent within my forms.py
class CreateEvent(forms.ModelForm):
class Meta:
model = Event
fields = ['title', 'start', 'end', 'description', 'category', 'created_by', 'rule', 'end_recurring_period']
widgets = {
'start': forms.SelectDateWidget()
}
EventCreateView within views.py
class EventCreateView(EventMixin, CreateView):
form_class = CreateEvent
model = Event
Does anyone know why i'm getting this error
Extra(If Allowed):
Within the EventCreateView its being passed "EventMixin" which looks like this
class EventMixin(object):
"""Mixin to handle event-related functions."""
model = Event
fields = '__all__'
@method_decorator(permission_required('calendarium.add_event'))
def dispatch(self, request, *args, **kwargs):
return super(EventMixin, self).dispatch(request, *args, **kwargs)
Can someone explain this to me?
Upvotes: 2
Views: 2114
Reputation: 308849
According to the docs, you can only import the SelectDateWidget
widget from django.forms
in Django 1.9+.
In earlier versions, you need to import it from django.forms.extras.widgets
.
First, add the import:
from django.forms.extras.widgets import SelectDateWidget
Then change the widgets
in your form to:
widgets = {
'start': SelectDateWidget(),
}
Upvotes: 1
Reputation: 78556
You are missing widgets
:
class CreateEvent(forms.ModelForm):
class Meta:
model = Event
fields = ['title', 'start', 'end', 'description', 'category', 'created_by', 'rule', 'end_recurring_period']
widgets = {
'start': forms.widgets.SelectDateWidget()
}
# ^^
On another note, I suspect the file containing that snippet is named forms.py
Upvotes: 2