I want to add an another autocomplete field to my model.form.
However, as soon as I add the autocomplete widget for the field "projektnummer"
'projektnummer': autocomplete.ModelSelect2(url='output:projekt-form-autocomplete'),
I get an wired template error I cannot make sense of. Do you have some ideas what I can do here?
Thank you very much! :)
error message:
AttributeError at /output/create/
'list' object has no attribute 'queryset'
Request Method: GET
Request URL: http://127.0.0.1:8000/output/create/
Django Version: 1.8.7
Exception Type: AttributeError
Exception Value:
'list' object has no attribute 'queryset'
Error during template rendering
In template /home/bjoern/Developement/Django/Outputmeldetool/venv_outputmeldetool/lib/python3.5/site-packages/crispy_forms/templates/bootstrap3/field.html, error at line 28
28 {% if field|is_checkbox and form_show_labels %}
forms.py
class KombiPublikationForm(forms.ModelForm):
typtyp = forms.ModelChoiceField(label='Vorauswahl Outputtyp', required = False,
queryset=KombiPublikationsTypTyp.objects.exclude(id__in=EXCLUDED_TYPTYP)
)
class Meta:
model = KombiPublikation
exclude = ['pub_sprache']
widgets = {
'freigabe': DateTimePicker(options={"format": "YYYY-MM-DD HH:mm", 'sideBySide': True}),
'typid': autocomplete.ModelSelect2(url='output:typ-autocomplete', forward=['typtyp']),
#adding following line generates the error:
'projektnummer': autocomplete.ModelSelect2(url='output:projekt-form-autocomplete'),
'monat': forms.NumberInput(),
}
def __init__(self, *args, **kwargs):
super(KombiPublikationForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.help_text_inline = True
self.helper.form_tag = False
self.helper.layout = Layout(
#a lot of layout stuff is here
)
edit:
I get the very same error message with a reduced test form without crispy forms. Just the plain model-form and the one autocomplete widget. So it seems to be unreleated to crispy forms, but related to the autocomplete widget.
class TestPublikationForm(forms.ModelForm):
class Meta:
model = KombiPublikation
exclude = ['pub_sprache']
widgets = {
'projektnummer': autocomplete.ModelSelect2(url='output:projekt-form-autocomplete'),
}
template.html
{{ form }}
error:
Exception Value: 'list' object has no attribute 'queryset'