@rennerocha Nowadays it should be possible to create a custom aggregate function: https://docs.djangoproject.com/en/5.1/ref/models/expressions/#creating-your-own-aggregate-functions (disclaimer: haven't tried it myself) and not resort to hacks (the article is from 2017 and back then this possibility didn't exist I think).