[Answered ]-Django: Retrieve a list of one model property for all distinct values of another property

1👍

Unfortunatly, this will depend on you DB.
If you’re using Postgresql you have access to ArrayAgg,
so the following will work :

results.values("color").annotate(scores=ArrayAgg("score"))

You’re using MySQL or MariaDB you can use GroupConcat.
But this won’t yield an array, it will yield a string with values separated by commas.
If this field will be manipulated using Python, you can do the following to get an array:

my_result.scores.split(",")

Leave a comment