Answers for "handle queries in ListView django"

1

handle queries in ListView django

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
Posted by: Guest on April-30-2020

Python Answers by Framework

Browse Popular Code Answers by Language