This is my model:
class People(models.Model):
name = models.CharField(max_length=100)
lastname = models.CharField(max_length=100)
In views.py
-When I try this one to count empty lastname fields:
People.objects.filter(lastname__isnull=True).count()
It returns always 0 event though there are some empty lastname fields.
Why I am getting 0, is there any problem with my code or Is there any other way to count empty fields in a table?
Your
CharFieldis most likely storing empty strings, not NULLDjango docs on null field value
Try changing your query to:
Empty is not the same as NULL. You would have needed to set your fields to have
null=True, which as the docs suggest, is not recommended for a CharField.