This is confusing me. 

In the topic guide on Aggregation 
(https://docs.djangoproject.com/en/1.10/topics/db/aggregation/#cheat-sheet), 
there is an example in the cheat sheet as follows:

# Cost per page>>> from django.db.models import F, FloatField, Sum>>> 
Book.objects.all().aggregate(...    price_per_page=Sum(F('price')/F('pages'), 
output_field=FloatField())){'price_per_page': 0.4470664529184653}


Does this mean:
i) Calculate the price per page for each book (F('price')/F('pages')) and 
then aggregate these over all books using the Sum function, or
ii) Aggregate the price using the Sum function, and also the number of 
pages using the Sum function, and them divide the former by the latter. 
?

Interpretation (i) is what the statement seems to say but this will result 
in a fairly meaningless number (the sum of cost per page per book, which is 
dependant on the number of books and doesn't mean much, and is certainly 
not an average price per page or anything similar).

Interpretation (ii) would make more sense (it calculates the overall price 
per page over all books), but the fact that the expression 
(F('price')/F('pages')) is inside the Sum function suggests that this is 
not what is happening.

Additionally, to aid my understanding, depending on which interpretation is 
correct, what would the statement be to implement the other interpretation? 
e.g. is interpretation (i) is what the above statement is doing, how would 
interpretation (ii) be implmented? Or vice versa....

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5205d351-90e9-4e8e-9ce5-59d27e850eda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to