Hello,

I've been looking into trying to order a relation based on some
arithmetic on each model's fields. This would ideally be at a database
level, and not a brute force python way. A simple example which I
can't seem to get to work is a sum of two fields.

For example, I want to sum a total amount of votes both good and bad
on some user submission. The solution I thought of would involve
something like:
query_set = UserSubmission.objects.all()
query_set.annotate(total_votes=F('bad_vote_count') + F
('good_vote_count'))
query_set = query_set.order_by('-total_votes')

However I can't get past the annotation part. F expressions seem to
work inside a filter method call, but fail miserably inside an
annotation.
" 'ExpressionNode' object has no attribute 'lookup' ".

Even if this is a bug (according to ticket 10972), I'm wondering if
there's any other possible solutions, or if I'm approaching this
problem completely the wrong way.

Thanks for your time in advance,

- Eric
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to