FieldError:CharField不支持的查找“ unaccent”或不允许在字段上加入

时间:2019-01-07 09:50:07

标签: django

我得到int main(){ int n, count =0; printf("enter an integer = "); scanf("%d", &n); printf("your number %d has ", n); while (n!=0){ n/=10; count++; } printf("%d digits", count); return 0; } 。任何帮助表示赞赏。有什么想法吗?

FieldError: Unsupported lookup 'unaccent' for CharField or join on the field not permitted

Traceback指向:  #template <form class="navbar-form navbar-left" method="GET" action="{% url 'search' %}" value="{{request.get.q}}"> <div class="form-group"> <input type="text" name="q" class="form-control" placeholder="Search" > </div> <button type="submit" class="btn btn-default">Submit</button> </form> #views.py def Search(request): queryset_list=Testimony.objects.all().order_by('timestamp') if request.user.is_staff or request.user.is_superuser: queryset_list=Testimony.objects.all() print('1') if request.method=='GET': query=request.GET.get("q") print('2') queryset_list = Testimony.objects.filter( Q(title__unaccent__lower__trigram_similar=query)| Q(body__unaccent__lower__trigram_similar=query)| Q(username__unaccent__lower__trigram_similar=query) #Q(firstname__unaccent__lower__trigram_similar__icontains=query) ).distinct().order_by('timestamp') print('3') paginator = Paginator(queryset_list, 20) page_request_var="page" page=request.GET.get(page_request_var) try: queryset=paginator.page(page) except PageNotAnInteger: queryset=paginator.page(1) except EmptyPage: queryset=paginator.page(paginator_num.pages) print('4') context={ "object_list": queryset, "title":"list", "page_request_var":page_request_var, } return render(request, 'search.html', {'queryset_list':queryset_list})

1 个答案:

答案 0 :(得分:0)

对于Django至少为1.11(source),而对于PostgreSQL至少为8.5(source

  • 在INSTALLED_APPS(settings.py)中添加“ django.contrib.postgres”行。
  • 激活“ unaccent”扩展名
    • 运行“创建扩展名不重音;”在PgAdmin(source)或...
    • 创建一个空迁移(./manage.py-清空您的.application.name),并使用以下内容(source)编辑生成的文件,最后运行./manage.py migration:

other reference

from django.contrib.postgres.operations import UnaccentExtension

class Migration(migrations.Migration):

dependencies = [
    (<snip>)
]

operations = [
    UnaccentExtension()
]

琐事:它不适用于admin.py,但适用于其他.py文件。