[Fixed]-Django – filtering by "certain value or None"

18👍

You can use Q values which allow you to combine multiple clauses in Django querysets.

Your query set would be something like:

from django.db.models import Q
MyElements.objects.all().filter(Q(value=None) | Q(value=myInt))

7👍

You can try OR statement:

from django.db.models import Q
MyElements.objects.filter(Q(value__isnull=True) | Q(value=myInt))

django documentation

Leave a comment