📜  在 ListView django 中处理查询 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:17.269000             🧑  作者: Mango

代码示例1
class ProfileList(ListView):
    template_name = 'your_template.html'
    model = Profile

    def get_queryset(self):
        query = self.request.GET.get('q')
        if query:
            object_list = self.model.objects.filter(name__icontains=query)
        else:
            object_list = self.model.objects.none()
        return object_list