1👍
✅
from django.db.models import Q
MyModel.objects.filter(~Q(grade__isnull=False) & ~Q(subject__exact=''))
edit:
you can take the idea from this here Django Filter Model by Dictionary
or you can make a copy from your data
for i in data.copy():
if data[i] == "" or data[i] == None:
data.pop(i)
or
for i in data.copy():
if not data[i]:
data.pop(i)
after that MyModel.objects.filter(**data)
Source:stackexchange.com