Categories
Python Answers

How to filter empty or NULL names in a Python Django QuerySet?

Spread the love

To filter empty or NULL names in a Python Django QuerySet, we can caill the exclude method.

For instance, we write

Name.objects.exclude(alias__isnull=True).exclude(alias__exact='')

to call exclude to exclude Name results that has alias set to null with

alias__isnull=True

And we exclude entries with alias set to an empty string by calling exclude with

alias__exact=''

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *