melbic
melbic

Reputation: 12217

Filter Queryset on empty ImageField

I have the following class:

class Book(models.Model):
    picture = models.ImageField(upload_to='books/', blank=True, null=True)
    ...

I now want to filter the books without a picture. I tried the following:

Book.objects.filter(picture__isnull=True)

The problem is, that the picture is an empty varchar ('') in the db and not null. What to do?

Upvotes: 20

Views: 6187

Answers (2)

0x4ndy
0x4ndy

Reputation: 1336

Just run the exclude method:

Books.objects.exclude(picture='')

Upvotes: 10

arulmr
arulmr

Reputation: 8836

Try this:

Book.objects.filter(picture__exact='')

Upvotes: 32

Related Questions