I have a Person model that sometimes has nothing in the birth_date field. Here is an example:
(Pdb) dude = Person.objects.get(pk=20) (Pdb) dude <Person: Bob Mandene> (Pdb) dude.birth_date (Pdb) dude.birth_date == None True
How to filter these entries with birth_date == None ?
I have already tried the following without success:
1: "birth_date__isnull" does not work.
Person.objects.filter(birth_date__isnull = True)
The record with identifier 20 is not returned below.
Person.objects.filter(birth_date = "")
How to filter in the None field? NULL and None seem to be different. When I see data using the pro sequel (mysql graphical client), I see "0000-00-00 00:00:00", and the following does not work either
(Pdb) ab=Patient.objects.filter(birth_date = "0000-00-00 00:00:00") ValidationError: [u"'0000-00-00 00:00:00' value has the correct format (YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ]) but it is an invalid date/time."]
model
class Person(models.Model): person_no = models.IntegerField(primary_key=True) locationid = models.IntegerField(null=True, db_column='LocationID', blank=True) address = models.ForeignKey('Address', db_column = 'address_no') birth_date = models.DateTimeField(null=True, blank=True) class Meta: managed = False db_table = 'person'
source share