Всем привет!
Не понятно, почему вылетает exception при попытке поиска по записям таблицы.
views.py
class SearchResultView(ListView, ProcessFormView):
...
def get(self, request, *args, **kwargs):
return super(SearchResultView, self).get(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
self.search_form = SearchForm(self.request.POST or None)
if self.search_form.is_valid():
search_term = u"%s" % self.search_form.cleaned_data['search_term']
g_list = None
if search_term:
try:
g_list = Gallery.objects.filter(
Q(article__icontains=search_term) |
Q(category__title__icontains=search_term) |
Q(tags__tag__icontains=search_term)
)
except ValueError as e:
print("Error! ", e.message)
return g_list
else:
return super(SearchResultView, self).post(request, *args, **kwargs)
...
Получаю ошибку:
too many values to unpack
Request Method: POST
Request URL: http://127.0.0.1:8000/gallery/search_result/
Django Version: 1.7.5
Exception Type: ValueError
Exception Value:
too many values to unpack
Exception Location: /.../lib/python2.7/site-packages/django/db/models/sql/query.py in build_filter, line 1179
Python Executable: /.../bin/python
Python Version: 2.7.9
Хотя, если выполнить запрос:
g_list = Gallery.objects.filter(
Q(article__icontains=search_term) |
Q(category__title__icontains=search_term) |
Q(tags__tag__icontains=search_term)
)
В чем может быть проблема?