If I have a QuerySet created from the following command:
data = ModelA.objects.values('date').annotate(total=Sum('amount'), average=Avg('amount'))
# <QuerySet [{'date': datetime.datetime(2016, 7, 15, 0, 0, tzinfo=<UTC>), 'total': 19982.0, 'average': 333.03333333333336}, {'date': datetime.datetime(2016, 7, 15, 0, 30, tzinfo=<UTC>), 'total': 18389.0, 'average': 306.48333333333335}]>
Is it possible to use data to create ModelBobjects from each hash inside the QuerySet?
I realize I could iterate and unpack the QuerySet and do it like so:
for q in data:
ModelB.objects.create(date=q['date'], total=q['total'], average=q['average'])
But is there a more elegant way? It seems redundant to iterate and create when they're almost in the bulk_create format.