get average from set of objects in django

Posted by dotty on Stack Overflow See other posts from Stack Overflow or by dotty
Published on 2010-04-22T09:38:07Z Indexed on 2010/04/22 9:43 UTC
Read the original article Hit count: 303

Filed under:
|
|

Hay, i have a simple rating system for a property. You give it a mark out of 5 (stars). The models are defined like this

def Property(models.Model)
    # stuff here

def Rating(models.Model)
    property = models.ForeignKey(Property)
    stars = models.IntegerField()

What i want to do is get a property, find all the Rating objects, collect them, then get the average 'stars' from them.

any ideas how to do this?

© Stack Overflow or respective owner

Related posts about django

Related posts about python