Search code examples
djangocriteriaratingweighted

Django multi-criteria weighted rating


I've started building an app in Django that will require multi-criteria weighted ratings. My issue is the exact same as this one from a few years ago, which unfortunately did not have any answer.

If anybody out there can give me some hints on how to make multi-criteria weighted ratings in Django, I would love to hear about it! I'm pretty new to the whole Django/Python world and come from a PHP background.

Thanks a lot!

PS: I did not put too much info in this thread, because the problem is already described on the other topic here. It's exactly the same thing.


Solution

  • The easiest solution for the weighted rating would be to add an additional field and populate it automatically in a custom save method on the rating object.

    As far as getting the overall average rating goes, you can either calculate it dynamically every time it's needed (easiest/most accurate method) using Django's aggregation queries, or you can try to maintain an average rating field that is updated each time a rating is added/deleted/updated (the more performant method if you're running a read-heavy service). See my answer here for more details on implementing these (using sums rather than averages) and more detail on the tradeoffs.