models.py
class KeySkills(models.Model):
skills = models.TextField()
versions = models.DecimalField(decimal_places=3,null=True,blank=True,max_digits=10,default=None)
experience = models.DecimalField(decimal_places=3,null=True,blank=True,max_digits=10,default=None)
user = models.ForeignKey(access_models.SeekerRegister,on_delete=models.CASCADE,related_name='key_skills',null=True,blank=True)
def __str__(self):
return "KeySkills"
查询:
KeySkills.objects.filter(skills__unaccent__icontains='python')
KeySkills.objects.filter(skills_text__search='python')
错误:
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 844, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 862, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1263, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1287, in _add_q
split_subq=split_subq,
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1225, in build_filter
condition = self.build_lookup(lookups, col, value)
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1080, in build_lookup
lhs = self.try_transform(lhs, name)
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1126, in try_transform
(name, lhs.output_field.__class__.__name__))
django.core.exceptions.FieldError: Unsupported lookup 'unaccent' for TextField or join on the field not permitted.
在这里,我正在尝试使用Django ORM查询进行搜索。 并尝试使用以上两种查询方式,但是我遇到了以上错误。
请查看我的代码。
答案 0 :(得分:1)
您需要在'django.contrib.postgres
中添加INSTALLED_APPS
'
另外,尝试此link
答案 1 :(得分:0)
您需要在INSTALLED_APPS中添加“ django.contrib.postgres”: 然后,您需要在数据库中安装扩展名“ unaccent”以执行此查询:
CREATE EXTENSION unaccent;
我是在pgadmin4内部执行查询的。