具有以下型号:
class Project(models.Model):
...
name = models.CharField(max_lenght=70)
short_description = models.CharField(max_length=135)
description = models.CharField(max_lenght=25000)
...
我只想使用一个输入来查看
name
,
short_description
和
description
.
例如,如果我有以下数据:
对象1:
name = "Amazing airplanes"
short_description = "This project wants to be ..."
description = "... ... ..."
对象2:
name = "Testing potatoes as batteries"
short_description = "... ... ... "
description = "... this project ..."
小精灵:
name = "project creator"
short_description = "... ... ..."
description = "... ... ..."
我只过滤一个输入
project
,因此我必须得到这三个对象。(如果一个对象在几个属性中有相同的单词,那么它只需要返回一次该对象)
我现在拥有的是:
class ProjectListFilter(django_filters.FilterSet):
name = django_filters.CharFilter(lookup_expr='icontains')
short_description = django_filters.CharFilter(lookup_expr='icontains')
description = django_filters.CharFilter(lookup_expr='icontains')
class Meta:
model = Project
fields = ['name', 'short_description', 'description']
queryset = Project.objects.all()
但这会产生3个输入,这是我试图回避的。