Q:

Searching PostgreSQL with Django and passing a null or empty string value

I'm searching Postgres as follows:
search_term = self.request.GET.get('search')
queryset = Package.objects.filter(package_description__search=search_term)

How do I make this return all objects if search_term is None or an empty string?
I've tried setting search_term to None or an empty string. 

A:

Django execute query only at moment when you try to get items of the query. So you can simple add if and combine your query
search_term = self.request.GET.get('search')
queryset = Package.objects.all()
if search_term:
    queryset = queryset.filter(package_description__search=search_term)

link to the doc querysets-are-lazy thank @bdoubleu

