我怎样才能向djang提出这个问题

2024-05-17 04:37:00 发布

您现在位置:Python中文网/ 问答频道 /正文

对于一个圣经网站,我可以搜索像《创世纪》这本书的所有诗句,或是“创世纪1”一章,但当我搜索像《创世纪1:1》这样的诗句时,就会出错

我怎样才能把1:1分开,这样我也能找到经文

    def get_queryset(self):
        query = self.request.GET.get('q')
        object_list = Verse.objects.all()
        if query:
            query = query.split()
            book = query[0]
            object_list = object_list.filter(book__icontains=book)
            if len(query) > 1:
                chapter = query[1]
                object_list = object_list.filter(chapter=chapter)
        return object_list

Tags: selfgetifobject网站圣经诗句def
1条回答
网友
1楼 · 发布于 2024-05-17 04:37:00

为章节筛选后添加此项

query[1] = query[1].split(":")
if len(query[1]) > 1
    objects_list = object_list.filter(verse=query[1][1])

相关问题 更多 >