Beginner Questions - February 22, 2019

I'm working on my first Django website and I'm making a rating system for items on it.

For the rating model, I want to calculate the average of an integer field, but I'm not sure where to do this calculation. I have a couple ideas.

  1. On each request, I can grab the object from the current context and use aggregate and Avg to get the average value and add it to the passing context.
  2. I can add a get_average_rating method to the model and do the calculation from the HTML/template.
  3. I can add an average_rating float field to the model that only updates when something is added to the table.

If anyone can provide some input, that'd be great!

/r/webdev Thread