I need to do an exclude on a django query to exclude records where both fields are blank but include if there is one or the other or both.
My model looks like
class Example(models.Model):
title = models.CharField(max_length=140, blank=True)
name = models.CharField(max_length=140, blank=True)
right now I am writing the query as
Example.objects.filter(general_query).exclude(title=u'').exclude(name=u'')
Or, simply put 2 conditions together under the same exclude()
:
Example.objects.filter(general_query).exclude(title=u'', name=u'')
Only both conditions are met will be excluded.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments