Sum computed column in Django QuerySet?

Not possible at the moment, there's a ticket for F() objects inside aggregation, but nothing promising.

Up vote 1 down vote favorite share g+ share fb share tw.

Given the following Contribution model: class Contribution(models. Model): start_time = models.DateTimeField() end_time = models. DateTimeField(null=True) is it possible, using the Django database API, to reproduce the following SQL statement?

SELECT SUM(end_time - start_time) AS total_duration FROM contribution; I've figured out this much: Contribution.objects. Aggregate(total_duration=models. Sum(? )) but I'm not sure about how to represent the end_time - start_time part.

Thanks! Sql django django-models django-queryset link|improve this question edited Mar 11 '10 at 23:09 asked Mar 11 '10 at 11:26harto8,48321333 86% accept rate.

Not possible at the moment, there's a ticket for F() objects inside aggregation, but nothing promising. The only way I see is to workaround by sum in python: sum(x1-x0 for x in Contribution.objects. Values_list('start_time', 'end_time')).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions