from django.db.models import F, ExpressionWrapper
resource_list = Resources.objects.filter(active=True, status__id=STATUS_PUBLIC_ID)
resource_list = resource_list.annotate(rank=ExpressionWrapper(
similar(keywords, F('title')), output_field=DecimalField()
)).filter(rank__gt=0).order_by('-rank').distinct()
def similar(a, b):
print(a, b)
return SequenceMatcher(None, a, b).ratio()
当我运行上面的代码时,它给了我一个错误 “ TypeError:'F'对象不可迭代” 资源是我拥有字段标题的模型 相似是检查2个字符串之间相似率的功能