Here is my example code that I used to create some example data:
importdatetimeasdt# don't care about timezones right now
expected={"energy":90.78559770167864,"irradiation":30.085498370965905}observed={"energy":10.78559770167864,"irradiation":20.085498370965905}today=dt.date.today()# Just create some identical objects, I don't think that this matters right now
DataPoint.objects.create(datetime=today,expected=expected,observed=observed)DataPoint.objects.create(datetime=today,expected=expected,observed=observed)DataPoint.objects.create(datetime=today,expected=expected,observed=observed)DataPoint.objects.create(datetime=today,expected=expected,observed=observed)date_from=today-dt.timedelta(days=4)date_to=today+dt.timedelta(days=3)object_data=DataPoint.objects.counts_and_sums(date_from,date_to)print(object_data)<QuerySet[{'day':datetime.datetime(2019,9,10,0,0,tzinfo=<DstTzInfo'Europe/Berlin'CEST+2:00:00DST>),'count':4,'observed_irradiation_total':80.3419934838636,'observed_energy_total':43.1423908067146,'expected_irradiation_total':120.341993483864,'expected_energy_total':363.142390806715}]>
And just for the records, my version, taken from the same shell:
Here are my code and I used Django 2.2.2, when I query data JSON value does come as None type and the count does bring value
query
my response
and my object looks like this when I query it with normal DataPoint.objects.all()
Unfortunately, all I can say is, it works for me.
Here is my example code that I used to create some example data:
And just for the records, my version, taken from the same shell:
The only thing I changed in your code, is that I removed the
plant_id
ForeignKey