django-postgres-extra
django-postgres-extra copied to clipboard
Support for HStore aggregates
I am not sure how this is going to work, but it should be possible to aggregate multiple columns into a hstore field:
results = MyModel.objects.annotate(thing=HStoreAgg(text=F('otherthing__text'), id=F('otherthing__id'))
for row in results:
print(row.thing.text)
print(row.thing.id)
This should also work in combination with ArrayAgg
:
results = MyModel.objects.annotate(things=ArrayAgg(HStoreAgg(text=F('otherthing__text'), id=F('otherthing__id')))
for row in results:
for thing in row.things:
print(row.thing.text)
print(row.thing.id)
Which results in: