我在 wagtail django 中搜索模型时遇到了一些危机
这是我的模型对象代码
recipes = RecipePage.objects.child_of(self).live().public() \
.select_related('listing_image')
extra_url_params = ''
error_message=False
filter_categories_raw = request.GET.get('categories')
filter_categories = False
filter_name = request.GET.get("name")
if filter_categories_raw:
filter_categories = []
filter_categories_raw = filter_categories_raw.split(",")
for fc in filter_categories_raw:
try:
value = int(fc)
filter_categories.append(value)
except ValueError:
filter_categories = False
error_message = "Invalid category value"
if filter_categories:
for filter_category in filter_categories:
recipes = recipes.filter(categories__category=filter_category)
if filter_name:
recipes = recipes.search(filter_name, recipes) <---- issue here
if not filter_name:
filter_name=""
我添加的我的 RecipePage 模型
search_fields = BasePage.search_fields + [
index.SearchField('title'),
]
现在当我这样做搜索时,
recipes = recipes.search(filter_name, recipes)
它给了我错误
无法将“RecipePage”对象隐式转换为 str
当我这样做时
recipes = recipes.search(filter_name, recipes.title) or recipes = recipes.search(filter_name, recipes.objects)
它给了我
“PageQuerySet”对象没有属性“title”
我被石头砸死了。我究竟做错了什么?