from dal import autocomplete
class EmotionAutocomplete(autocomplete.Select2ListView):
def get_list(self):
return ['Sad', 'Happy', 'Angry', 'Neutral']
# This was my original view that worked fine before trying to get autocomplete for cat_emotion field
def was_emotion(request):
if request.method == 'POST':
form = WasEmotionForm(request.POST)
if form.is_valid():
attention = form.cleaned_data['attention']
was_emotion = form.cleaned_data['likert_was_emotion']
cat_emotion = form.cleaned_data['cat_emotion']
judge_obj = Judge(attention=attention, was_emotion=was_emotion, cat_emotion=cat_emotion)
judge_obj.save()
return HttpResponseRedirect('/evaluation/')
else:
form = WasEmotionForm()
return render(request, 'wasEmotion.html', {'form': form})
urlpatterns = [
url(r'^wasEmotion/$', views.was_emotion, name='was_emotion'),
...
url(r'^emotion-autocomplete/$', views.EmotionAutocomplete.as_view(), name='emotion-autocomplete'),
]
def get_choice_list():
return ['Sad', 'Happy', 'Angry', 'Neutral']
class WasEmotionForm(forms.Form):
attention = forms.ChoiceField(label=" ", initial='1', widget=forms.RadioSelect, choices=(
('1', 'Strongly disagree'), ('2', 'Disagree'), ('3', 'Neither agree nor disagree'), ('4', 'Agree'),
('5', 'Strongly agree')))
likert_was_emotion = forms.ChoiceField(label=" ", initial='1', widget=forms.RadioSelect, choices=(
('1', 'Strongly disagree'), ('2', 'Disagree'), ('3', 'Neither agree nor disagree'), ('4', 'Agree'),
('5', 'Strongly agree')))
cat_emotion = autocomplete.Select2ListChoiceField(
choice_list=get_choice_list,
widget=autocomplete.ListSelect2(url='emotion-autocomplete'))
{"results": [{"text": "Sad", "id": "Sad"}, {"text": "Happy", "id": "Happy"}, {"text": "Angry", "id": "Angry"}, {"text": "Neutral", "id": "Neutral"}]}
But 127.0.0.1:8000/wasEmotion/ gives:
I know I have done many things different from the example but I need to get this integrated in my previous code. Any help will be very much appreciated.
--
You received this message because you are subscribed to the Google Groups "yourlabs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yourlabs+u...@googlegroups.com.
To post to this group, send email to your...@googlegroups.com.
Visit this group at https://groups.google.com/group/yourlabs.
To view this discussion on the web visit https://groups.google.com/d/msgid/yourlabs/5ff89ca1-a74a-4a46-8939-05b2dae7020d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
ROOT_URLCONF = 'galatea.urls'
# galatea/urls.py
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('evalemo.urls')),
]# evalemo/urls.py
app_name = 'evalemo'
urlpatterns = [
url(r'^wasEmotion/$', views.was_emotion, name='was_emotion'),
...
url(r'^emotion-autocomplete/$', views.EmotionAutocomplete.as_view(), name='emotion-autocomplete'),
]
To unsubscribe from this group and stop receiving emails from it, send an email to your...@googlegroups.com.