Django trigram_similar
I've been trying to implement trigram_similar functionality in my Django backend code. I get an error
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
web_1 | response = get_response(request)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
web_1 | response = self.process_exception_by_middleware(e, request)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
web_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
web_1 | return view_func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
web_1 | return self.dispatch(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 489, in dispatch
web_1 | response = self.handle_exception(exc)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 449, in handle_exception
web_1 | self.raise_uncaught_exception(exc)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 486, in dispatch
web_1 | response = handler(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/generics.py", line 201, in get
web_1 | return self.list(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/mixins.py", line 40, in list
web_1 | queryset = self.filter_queryset(self.get_queryset())
web_1 | File "/usr/local/lib/python3.6/site-packages/profilehooks.py", line 239, in new_fn
web_1 | return fp(*args, **kw)
web_1 | File "/usr/local/lib/python3.6/site-packages/profilehooks.py", line 347, in call
web_1 | return profiler.runcall(self.fn, *args, **kw)
web_1 | File "/usr/local/lib/python3.6/cProfile.py", line 109, in runcall
web_1 | return func(*args, **kw)
web_1 | File "/code/src/users/views.py", line 266, in filter_queryset
web_1 | major__name__trigram_similar = "CS"
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 784, in filter
web_1 | return self._filter_or_exclude(False, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 802, in _filter_or_exclude
web_1 | clone.query.add_q(Q(*args, **kwargs))
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1250, in add_q
web_1 | clause, _ = self._add_q(q_object, self.used_aliases)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1276, in _add_q
web_1 | allow_joins=allow_joins, split_subq=split_subq,
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1210, in build_filter
web_1 | condition = self.build_lookup(lookups, col, value)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1102, in build_lookup
web_1 | lhs = self.try_transform(lhs, name, lookups)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1120, in try_transform
web_1 | (name, lhs.output_field.class.name))
web_1 | django.core.exceptions.FieldError: Unsupported lookup 'trigram_similar' for CharField or join on the field not permitted.
web_1 | 2018-11-11 19:03:58,144 ERROR Internal Server Error: /mentors/
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
web_1 | response = get_response(request)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
web_1 | response = self.process_exception_by_middleware(e, request)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
web_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
web_1 | return view_func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
web_1 | return self.dispatch(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 489, in dispatch
web_1 | response = self.handle_exception(exc)
web_1 | File "/usr/local/lib/python3.6/site-
packages/rest_framework/views.py", line 449, in handle_exception
web_1 | self.raise_uncaught_exception(exc)
web_1 | File "/usr/local/lib/python3.6/site-
packages/rest_framework/views.py", line 486, in dispatch
web_1 | response = handler(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-
packages/rest_framework/generics.py", line 201, in get
web_1 | return self.list(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-
packages/rest_framework/mixins.py", line 40, in list
web_1 | queryset = self.filter_queryset(self.get_queryset())
web_1 | File "/usr/local/lib/python3.6/site-
packages/profilehooks.py", line 239, in new_fn
web_1 | return fp(*args, **kw)
web_1 | File "/usr/local/lib/python3.6/site-
packages/profilehooks.py", line 347, in call
web_1 | return profiler.runcall(self.fn, *args, **kw)
web_1 | File "/usr/local/lib/python3.6/cProfile.py", line 109,
in runcall
web_1 | return func(*args, **kw)
web_1 | File "/code/src/users/views.py", line 266, in
filter_queryset
web_1 | major__name__trigram_similar = "CS"
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/query.py", line 784, in filter
web_1 | return self._filter_or_exclude(False, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/query.py", line 802, in _filter_or_exclude
web_1 | clone.query.add_q(Q(*args, **kwargs))
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1250, in add_q
web_1 | clause, _ = self._add_q(q_object, self.used_aliases)
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1276, in _add_q
web_1 | allow_joins=allow_joins, split_subq=split_subq,
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1210, in build_filter
web_1 | condition = self.build_lookup(lookups, col, value)
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1102, in build_lookup
web_1 | lhs = self.try_transform(lhs, name, lookups)
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1120, in try_transform
web_1 | (name, lhs.output_field.class.name))
web_1 | django.core.exceptions.FieldError: Unsupported lookup 'trigram_similar' for CharField or join on the field not permitted.
I've followed the instructions on this page https://docs.djangoproject.com/en/2.0/ref/contrib/postgres/lookups/ but to no avail. I have properly installed the dependencies and added the extra files.
for item in query:
item_alias = trans_dict.get(item.lower(),item)
major_alias = major_dict.get(item.lower(),item)
queryset = queryset.filter(
major__name__trigram_similar = major_alias
)
SOS!
python django pg-trgm
add a comment |
I've been trying to implement trigram_similar functionality in my Django backend code. I get an error
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
web_1 | response = get_response(request)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
web_1 | response = self.process_exception_by_middleware(e, request)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
web_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
web_1 | return view_func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
web_1 | return self.dispatch(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 489, in dispatch
web_1 | response = self.handle_exception(exc)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 449, in handle_exception
web_1 | self.raise_uncaught_exception(exc)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 486, in dispatch
web_1 | response = handler(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/generics.py", line 201, in get
web_1 | return self.list(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/mixins.py", line 40, in list
web_1 | queryset = self.filter_queryset(self.get_queryset())
web_1 | File "/usr/local/lib/python3.6/site-packages/profilehooks.py", line 239, in new_fn
web_1 | return fp(*args, **kw)
web_1 | File "/usr/local/lib/python3.6/site-packages/profilehooks.py", line 347, in call
web_1 | return profiler.runcall(self.fn, *args, **kw)
web_1 | File "/usr/local/lib/python3.6/cProfile.py", line 109, in runcall
web_1 | return func(*args, **kw)
web_1 | File "/code/src/users/views.py", line 266, in filter_queryset
web_1 | major__name__trigram_similar = "CS"
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 784, in filter
web_1 | return self._filter_or_exclude(False, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 802, in _filter_or_exclude
web_1 | clone.query.add_q(Q(*args, **kwargs))
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1250, in add_q
web_1 | clause, _ = self._add_q(q_object, self.used_aliases)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1276, in _add_q
web_1 | allow_joins=allow_joins, split_subq=split_subq,
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1210, in build_filter
web_1 | condition = self.build_lookup(lookups, col, value)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1102, in build_lookup
web_1 | lhs = self.try_transform(lhs, name, lookups)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1120, in try_transform
web_1 | (name, lhs.output_field.class.name))
web_1 | django.core.exceptions.FieldError: Unsupported lookup 'trigram_similar' for CharField or join on the field not permitted.
web_1 | 2018-11-11 19:03:58,144 ERROR Internal Server Error: /mentors/
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
web_1 | response = get_response(request)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
web_1 | response = self.process_exception_by_middleware(e, request)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
web_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
web_1 | return view_func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
web_1 | return self.dispatch(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 489, in dispatch
web_1 | response = self.handle_exception(exc)
web_1 | File "/usr/local/lib/python3.6/site-
packages/rest_framework/views.py", line 449, in handle_exception
web_1 | self.raise_uncaught_exception(exc)
web_1 | File "/usr/local/lib/python3.6/site-
packages/rest_framework/views.py", line 486, in dispatch
web_1 | response = handler(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-
packages/rest_framework/generics.py", line 201, in get
web_1 | return self.list(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-
packages/rest_framework/mixins.py", line 40, in list
web_1 | queryset = self.filter_queryset(self.get_queryset())
web_1 | File "/usr/local/lib/python3.6/site-
packages/profilehooks.py", line 239, in new_fn
web_1 | return fp(*args, **kw)
web_1 | File "/usr/local/lib/python3.6/site-
packages/profilehooks.py", line 347, in call
web_1 | return profiler.runcall(self.fn, *args, **kw)
web_1 | File "/usr/local/lib/python3.6/cProfile.py", line 109,
in runcall
web_1 | return func(*args, **kw)
web_1 | File "/code/src/users/views.py", line 266, in
filter_queryset
web_1 | major__name__trigram_similar = "CS"
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/query.py", line 784, in filter
web_1 | return self._filter_or_exclude(False, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/query.py", line 802, in _filter_or_exclude
web_1 | clone.query.add_q(Q(*args, **kwargs))
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1250, in add_q
web_1 | clause, _ = self._add_q(q_object, self.used_aliases)
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1276, in _add_q
web_1 | allow_joins=allow_joins, split_subq=split_subq,
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1210, in build_filter
web_1 | condition = self.build_lookup(lookups, col, value)
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1102, in build_lookup
web_1 | lhs = self.try_transform(lhs, name, lookups)
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1120, in try_transform
web_1 | (name, lhs.output_field.class.name))
web_1 | django.core.exceptions.FieldError: Unsupported lookup 'trigram_similar' for CharField or join on the field not permitted.
I've followed the instructions on this page https://docs.djangoproject.com/en/2.0/ref/contrib/postgres/lookups/ but to no avail. I have properly installed the dependencies and added the extra files.
for item in query:
item_alias = trans_dict.get(item.lower(),item)
major_alias = major_dict.get(item.lower(),item)
queryset = queryset.filter(
major__name__trigram_similar = major_alias
)
SOS!
python django pg-trgm
Please include your error message as text, not a screenshot. Also include the relevant python code where you use trigram_similar. Minimal, Complete, and Verifiable example
– Håken Lid
Nov 11 '18 at 19:26
'FieldError at /mentors/ Unsupported lookup 'trigram_similar' for CharField or join on the field not permitted. Request Method: GET Request URL: localhost:8000/mentors/?query=cs Django Version: 1.11.7 Python Executable: /usr/local/bin/python3 Python Version: 3.6.7'
– nwar1994
Nov 11 '18 at 19:31
Edit your question and add the full traceback there, not in a comment. Also include the relevant python code. The traceback includes file names and line numbers.
– Håken Lid
Nov 11 '18 at 19:33
add a comment |
I've been trying to implement trigram_similar functionality in my Django backend code. I get an error
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
web_1 | response = get_response(request)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
web_1 | response = self.process_exception_by_middleware(e, request)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
web_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
web_1 | return view_func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
web_1 | return self.dispatch(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 489, in dispatch
web_1 | response = self.handle_exception(exc)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 449, in handle_exception
web_1 | self.raise_uncaught_exception(exc)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 486, in dispatch
web_1 | response = handler(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/generics.py", line 201, in get
web_1 | return self.list(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/mixins.py", line 40, in list
web_1 | queryset = self.filter_queryset(self.get_queryset())
web_1 | File "/usr/local/lib/python3.6/site-packages/profilehooks.py", line 239, in new_fn
web_1 | return fp(*args, **kw)
web_1 | File "/usr/local/lib/python3.6/site-packages/profilehooks.py", line 347, in call
web_1 | return profiler.runcall(self.fn, *args, **kw)
web_1 | File "/usr/local/lib/python3.6/cProfile.py", line 109, in runcall
web_1 | return func(*args, **kw)
web_1 | File "/code/src/users/views.py", line 266, in filter_queryset
web_1 | major__name__trigram_similar = "CS"
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 784, in filter
web_1 | return self._filter_or_exclude(False, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 802, in _filter_or_exclude
web_1 | clone.query.add_q(Q(*args, **kwargs))
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1250, in add_q
web_1 | clause, _ = self._add_q(q_object, self.used_aliases)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1276, in _add_q
web_1 | allow_joins=allow_joins, split_subq=split_subq,
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1210, in build_filter
web_1 | condition = self.build_lookup(lookups, col, value)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1102, in build_lookup
web_1 | lhs = self.try_transform(lhs, name, lookups)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1120, in try_transform
web_1 | (name, lhs.output_field.class.name))
web_1 | django.core.exceptions.FieldError: Unsupported lookup 'trigram_similar' for CharField or join on the field not permitted.
web_1 | 2018-11-11 19:03:58,144 ERROR Internal Server Error: /mentors/
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
web_1 | response = get_response(request)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
web_1 | response = self.process_exception_by_middleware(e, request)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
web_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
web_1 | return view_func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
web_1 | return self.dispatch(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 489, in dispatch
web_1 | response = self.handle_exception(exc)
web_1 | File "/usr/local/lib/python3.6/site-
packages/rest_framework/views.py", line 449, in handle_exception
web_1 | self.raise_uncaught_exception(exc)
web_1 | File "/usr/local/lib/python3.6/site-
packages/rest_framework/views.py", line 486, in dispatch
web_1 | response = handler(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-
packages/rest_framework/generics.py", line 201, in get
web_1 | return self.list(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-
packages/rest_framework/mixins.py", line 40, in list
web_1 | queryset = self.filter_queryset(self.get_queryset())
web_1 | File "/usr/local/lib/python3.6/site-
packages/profilehooks.py", line 239, in new_fn
web_1 | return fp(*args, **kw)
web_1 | File "/usr/local/lib/python3.6/site-
packages/profilehooks.py", line 347, in call
web_1 | return profiler.runcall(self.fn, *args, **kw)
web_1 | File "/usr/local/lib/python3.6/cProfile.py", line 109,
in runcall
web_1 | return func(*args, **kw)
web_1 | File "/code/src/users/views.py", line 266, in
filter_queryset
web_1 | major__name__trigram_similar = "CS"
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/query.py", line 784, in filter
web_1 | return self._filter_or_exclude(False, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/query.py", line 802, in _filter_or_exclude
web_1 | clone.query.add_q(Q(*args, **kwargs))
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1250, in add_q
web_1 | clause, _ = self._add_q(q_object, self.used_aliases)
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1276, in _add_q
web_1 | allow_joins=allow_joins, split_subq=split_subq,
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1210, in build_filter
web_1 | condition = self.build_lookup(lookups, col, value)
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1102, in build_lookup
web_1 | lhs = self.try_transform(lhs, name, lookups)
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1120, in try_transform
web_1 | (name, lhs.output_field.class.name))
web_1 | django.core.exceptions.FieldError: Unsupported lookup 'trigram_similar' for CharField or join on the field not permitted.
I've followed the instructions on this page https://docs.djangoproject.com/en/2.0/ref/contrib/postgres/lookups/ but to no avail. I have properly installed the dependencies and added the extra files.
for item in query:
item_alias = trans_dict.get(item.lower(),item)
major_alias = major_dict.get(item.lower(),item)
queryset = queryset.filter(
major__name__trigram_similar = major_alias
)
SOS!
python django pg-trgm
I've been trying to implement trigram_similar functionality in my Django backend code. I get an error
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
web_1 | response = get_response(request)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
web_1 | response = self.process_exception_by_middleware(e, request)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
web_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
web_1 | return view_func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
web_1 | return self.dispatch(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 489, in dispatch
web_1 | response = self.handle_exception(exc)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 449, in handle_exception
web_1 | self.raise_uncaught_exception(exc)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 486, in dispatch
web_1 | response = handler(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/generics.py", line 201, in get
web_1 | return self.list(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/mixins.py", line 40, in list
web_1 | queryset = self.filter_queryset(self.get_queryset())
web_1 | File "/usr/local/lib/python3.6/site-packages/profilehooks.py", line 239, in new_fn
web_1 | return fp(*args, **kw)
web_1 | File "/usr/local/lib/python3.6/site-packages/profilehooks.py", line 347, in call
web_1 | return profiler.runcall(self.fn, *args, **kw)
web_1 | File "/usr/local/lib/python3.6/cProfile.py", line 109, in runcall
web_1 | return func(*args, **kw)
web_1 | File "/code/src/users/views.py", line 266, in filter_queryset
web_1 | major__name__trigram_similar = "CS"
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 784, in filter
web_1 | return self._filter_or_exclude(False, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 802, in _filter_or_exclude
web_1 | clone.query.add_q(Q(*args, **kwargs))
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1250, in add_q
web_1 | clause, _ = self._add_q(q_object, self.used_aliases)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1276, in _add_q
web_1 | allow_joins=allow_joins, split_subq=split_subq,
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1210, in build_filter
web_1 | condition = self.build_lookup(lookups, col, value)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1102, in build_lookup
web_1 | lhs = self.try_transform(lhs, name, lookups)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1120, in try_transform
web_1 | (name, lhs.output_field.class.name))
web_1 | django.core.exceptions.FieldError: Unsupported lookup 'trigram_similar' for CharField or join on the field not permitted.
web_1 | 2018-11-11 19:03:58,144 ERROR Internal Server Error: /mentors/
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
web_1 | response = get_response(request)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
web_1 | response = self.process_exception_by_middleware(e, request)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
web_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
web_1 | return view_func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
web_1 | return self.dispatch(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 489, in dispatch
web_1 | response = self.handle_exception(exc)
web_1 | File "/usr/local/lib/python3.6/site-
packages/rest_framework/views.py", line 449, in handle_exception
web_1 | self.raise_uncaught_exception(exc)
web_1 | File "/usr/local/lib/python3.6/site-
packages/rest_framework/views.py", line 486, in dispatch
web_1 | response = handler(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-
packages/rest_framework/generics.py", line 201, in get
web_1 | return self.list(request, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-
packages/rest_framework/mixins.py", line 40, in list
web_1 | queryset = self.filter_queryset(self.get_queryset())
web_1 | File "/usr/local/lib/python3.6/site-
packages/profilehooks.py", line 239, in new_fn
web_1 | return fp(*args, **kw)
web_1 | File "/usr/local/lib/python3.6/site-
packages/profilehooks.py", line 347, in call
web_1 | return profiler.runcall(self.fn, *args, **kw)
web_1 | File "/usr/local/lib/python3.6/cProfile.py", line 109,
in runcall
web_1 | return func(*args, **kw)
web_1 | File "/code/src/users/views.py", line 266, in
filter_queryset
web_1 | major__name__trigram_similar = "CS"
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/query.py", line 784, in filter
web_1 | return self._filter_or_exclude(False, *args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/query.py", line 802, in _filter_or_exclude
web_1 | clone.query.add_q(Q(*args, **kwargs))
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1250, in add_q
web_1 | clause, _ = self._add_q(q_object, self.used_aliases)
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1276, in _add_q
web_1 | allow_joins=allow_joins, split_subq=split_subq,
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1210, in build_filter
web_1 | condition = self.build_lookup(lookups, col, value)
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1102, in build_lookup
web_1 | lhs = self.try_transform(lhs, name, lookups)
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/models/sql/query.py", line 1120, in try_transform
web_1 | (name, lhs.output_field.class.name))
web_1 | django.core.exceptions.FieldError: Unsupported lookup 'trigram_similar' for CharField or join on the field not permitted.
I've followed the instructions on this page https://docs.djangoproject.com/en/2.0/ref/contrib/postgres/lookups/ but to no avail. I have properly installed the dependencies and added the extra files.
for item in query:
item_alias = trans_dict.get(item.lower(),item)
major_alias = major_dict.get(item.lower(),item)
queryset = queryset.filter(
major__name__trigram_similar = major_alias
)
SOS!
python django pg-trgm
python django pg-trgm
edited Nov 11 '18 at 19:43
nwar1994
asked Nov 11 '18 at 19:15
nwar1994nwar1994
134
134
Please include your error message as text, not a screenshot. Also include the relevant python code where you use trigram_similar. Minimal, Complete, and Verifiable example
– Håken Lid
Nov 11 '18 at 19:26
'FieldError at /mentors/ Unsupported lookup 'trigram_similar' for CharField or join on the field not permitted. Request Method: GET Request URL: localhost:8000/mentors/?query=cs Django Version: 1.11.7 Python Executable: /usr/local/bin/python3 Python Version: 3.6.7'
– nwar1994
Nov 11 '18 at 19:31
Edit your question and add the full traceback there, not in a comment. Also include the relevant python code. The traceback includes file names and line numbers.
– Håken Lid
Nov 11 '18 at 19:33
add a comment |
Please include your error message as text, not a screenshot. Also include the relevant python code where you use trigram_similar. Minimal, Complete, and Verifiable example
– Håken Lid
Nov 11 '18 at 19:26
'FieldError at /mentors/ Unsupported lookup 'trigram_similar' for CharField or join on the field not permitted. Request Method: GET Request URL: localhost:8000/mentors/?query=cs Django Version: 1.11.7 Python Executable: /usr/local/bin/python3 Python Version: 3.6.7'
– nwar1994
Nov 11 '18 at 19:31
Edit your question and add the full traceback there, not in a comment. Also include the relevant python code. The traceback includes file names and line numbers.
– Håken Lid
Nov 11 '18 at 19:33
Please include your error message as text, not a screenshot. Also include the relevant python code where you use trigram_similar. Minimal, Complete, and Verifiable example
– Håken Lid
Nov 11 '18 at 19:26
Please include your error message as text, not a screenshot. Also include the relevant python code where you use trigram_similar. Minimal, Complete, and Verifiable example
– Håken Lid
Nov 11 '18 at 19:26
'FieldError at /mentors/ Unsupported lookup 'trigram_similar' for CharField or join on the field not permitted. Request Method: GET Request URL: localhost:8000/mentors/?query=cs Django Version: 1.11.7 Python Executable: /usr/local/bin/python3 Python Version: 3.6.7'
– nwar1994
Nov 11 '18 at 19:31
'FieldError at /mentors/ Unsupported lookup 'trigram_similar' for CharField or join on the field not permitted. Request Method: GET Request URL: localhost:8000/mentors/?query=cs Django Version: 1.11.7 Python Executable: /usr/local/bin/python3 Python Version: 3.6.7'
– nwar1994
Nov 11 '18 at 19:31
Edit your question and add the full traceback there, not in a comment. Also include the relevant python code. The traceback includes file names and line numbers.
– Håken Lid
Nov 11 '18 at 19:33
Edit your question and add the full traceback there, not in a comment. Also include the relevant python code. The traceback includes file names and line numbers.
– Håken Lid
Nov 11 '18 at 19:33
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252263%2fdjango-trigram-similar%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252263%2fdjango-trigram-similar%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please include your error message as text, not a screenshot. Also include the relevant python code where you use trigram_similar. Minimal, Complete, and Verifiable example
– Håken Lid
Nov 11 '18 at 19:26
'FieldError at /mentors/ Unsupported lookup 'trigram_similar' for CharField or join on the field not permitted. Request Method: GET Request URL: localhost:8000/mentors/?query=cs Django Version: 1.11.7 Python Executable: /usr/local/bin/python3 Python Version: 3.6.7'
– nwar1994
Nov 11 '18 at 19:31
Edit your question and add the full traceback there, not in a comment. Also include the relevant python code. The traceback includes file names and line numbers.
– Håken Lid
Nov 11 '18 at 19:33