You need to specify the field of the value in your ORM statement.  I don’t know 
what your field name is, but this assumes that it is “value”:
aggregate(Sum(‘payment__value’))

From: [email protected] [mailto:[email protected]] On 
Behalf Of Gerald Brown
Sent: Monday, August 6, 2018 8:29 AM
To: Django users
Subject: Django ORM aggregate Sum function on foreign key

Greetings:

I am having a problem using the above function.

In my table I have a field payment that is a foreign key to a payment table.

When I try to use aggregate(sum('payment')) it gives me the sum of the foreign 
key, not the value from the payment table.
Currently I have 9 records in my test DB each one has a foreign key of 3 so I 
get a sum of 27 not 2,250 that I should be getting.

This table also has a foreign key to the customer table and it returns the 
customer not the foreign key number.

The thought I had was to make that foreign key an integer field and then the 
user would have to enter a number instead of selecting it from a list, prone to 
operator errors,

Any ideas on how I can get the correct totals using ORM.

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]<mailto:[email protected]>.
To post to this group, send email to 
[email protected]<mailto:[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/c47e4bb7-626c-4b07-9ab5-55d68fe4d566%40googlegroups.com<https://groups.google.com/d/msgid/django-users/c47e4bb7-626c-4b07-9ab5-55d68fe4d566%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

-- 
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/3a17d4eeeb804cc89c4cda5eaca8b050%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.

Reply via email to