Django: Summing values

Posted by Anry on Stack Overflow See other posts from Stack Overflow or by Anry
Published on 2010-05-13T16:07:17Z Indexed on 2010/05/13 16:24 UTC
Read the original article Hit count: 270

Filed under:
|

I have a two Model - Project and Cost.

class Project(models.Model):
    title = models.CharField(max_length=150)
    url = models.URLField()
    manager = models.ForeignKey(User)

class Cost(models.Model):
    project = models.ForeignKey(Project)
    cost = models.FloatField()
    date = models.DateField()

I must return the sum of costs for each project. view.py:

from mypm.costs.models import Project, Cost
from django.shortcuts import render_to_response
from django.db.models import Avg, Sum

def index(request):
    #...
    return render_to_response('index.html',...

How?

© Stack Overflow or respective owner

Related posts about django

Related posts about python