Given the model:
class Person(models.Model):
name = models.CharField(max_length=200)
resume = models.FileField(upload_to='resumes/', blank=True, null=True)
I have created a few people via:
Person.objects.create(name='Brad')
Person.objects.create(name='Tony')
How do I write a query using the ORM to give me people that don’t have a resume. I’ve tried the following, but all fail to return the desired result:
>>> Person.objects.filter(resume=None)
[]
>>> Person.objects.filter(resume__exact=None)
[]
>>> Person.objects.filter(resume__isnull=True)
[]
I’m pretty sure that you filter by empty string
''The underlying field is a
CharField()as mentioned by the docs forFilefield.Django stores blanks for CharFields as empty strings not NULL, so filtering for empty strings gets you Persons with no resumes.
Model Field References regarding Null