I have a table with metadata on fieldmeasurement in which a fields 'startDate' is of type datetime. The value can be empty, when no info is available. I would like to run some statistics on this field, and get min and max value (i.e. the oldest measurements available over all records). No problem for the Max, but for Min the aggregation returns None (the value in empty fields).
So my idea is to filter these records from the queryset, before running the aggregate. I cannot find how to do this.
I have tried
oldestdate = Measurement.object.filter(startDate__isNull=True).aggregate(Min('startDate'))['startDate__min']
Any idea what's wrong, or how to do this?
EDIT: some more testing reveals that:
Measurement.objects.filter(startDate_isnull=True) -> only records with startDate = None
Measurement.objects.filter(startDate_isnull=False) -> all records, also the ones with startDate = None.
Measurement.objects.exclude(startDate__isnull=False) -> only records with startDate = None
Measurement.objects.exclude(startDate__isnull=True) -> shows all records (also startDate == None)