#20930: Arithmetic operations on aggregates
----------------------------------------------+--------------------
     Reporter:  debanshuk                     |      Owner:  nobody
         Type:  New feature                   |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  master
     Severity:  Normal                        |   Keywords:
 Triage Stage:  Unreviewed                    |  Has patch:  1
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+--------------------
 In many cases one may require to do simple arithmetic operations (+, -, *,
 /) on aggregated (with numbers or other aggregates).
 Eg. For model `Xyz`:

 {{{
 class Xyz(models.Model):
     a = models.IntegerField()
     b = models.IntegerField()
 }}}

 If I want to find percent ratio of sum of all `a` and sum of all `b`, I
 can write:

 {{{
 Xyz.objects.aggregate(ratio_percent=Sum('a')/Sum('b')*100)
 }}}

 This type of functionality has been implemented in this commit
 
https://github.com/debanshuk/django/commit/722f7a4a17870fe1ffb6c207153d1fca6388a401

 More operations (like pow) can also be added.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/20930>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.875c4988492f82854ca595781b2d6787%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to