haystack 自定义

 
from haystack.forms import SearchForm
class Search(View):

    def get(self, request):
        """
        获取搜索结果
        """
        q = request.GET.get("q")
        sform = SearchForm({"q":q})
        posts = sform.search()
        posts = posts.models(Goods,) # 指定搜索表
        posts_count = posts.count()
        posts = posts[1: 15]
        pub_info_list = []
        for i in posts:
            # num_id = int(re.search(r'\d+', i.id).group())
            pub_info_list.append(i.pk)
        return JsonResponse({"ret": pub_info_list})
发布了73 篇原创文章 · 获赞 41 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/weixin_37989267/article/details/90379153