Django exclude both fields blank

Tyler

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'')
Anzel

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.

edited at
0

Comments

0 comments
Login to comment

Related