Dean Christian Armada Dean Christian Armada - 1 year ago 72
Python Question

Finding all posts without tags in Django Postgres ArrayField

Just like what my title says, I want to see all my posts without any tags. However none of the following ORM is working:

x = PostTagging.obejcts.filter(tags=[])
x = PostTagging.objects.filter(tags__len=0)

All I get as a return is:

<QuerySet []>

Here is my model:

class PostTagging(models.Model):
title = models.CharField(max_length=50)
tags = ArrayField(models.CharField(max_length=200), blank=True, null=True)

def __unicode__(self):
return self.title

Here is my ORM for creating the blank tag:

PostTagging.objects.create(title='Fifth Post')

Answer Source

PostTagging.objects.filter(tags__isnull=True) is the best way

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download