I\'m pretty new to Django and come from the PHP world. I\'m trying to \'add\' a field to a queryset after computing things, and don\'t know how to do it. In PHP I would just add
You can set anything on a python object:
for obj in self.model.objects.all() :
obj.score = total_score / total_posts
This will work even if obj does not have a score attribute. In the template request it like so:
{{ obj.score }}
Yes, it's that simple. However, if the calculations you're doing can be done in the database, you should look into annotate.