How to pass to the Sum() function (ORM) more than one field?

My problem:

class Model1(models.Model):
    name = models.CharField(u'Name', max_length=255)

class Model2(models.Model):
    fk1 = models.ForeignKey(Model1, related_name='fk_1')
    fk2 = models.ForeignKey(Model1, related_name='fk_2')

I want to sort data by sum of fk1 and fk2 field.

Model1.objects.annotate(myfk1=Count('fk1', distinct=True), myfk2=Count
('fk2', distinct=True)).annotate(my_sum=Sum('myfk1+myfk2')).order_by('-
my_sum')

Thanks for help.

regards.
--~--~---------~--~----~------------~-------~--~----~
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