Created
March 22, 2017 17:46
-
-
Save jourdanrodrigues/e67ecc8839f47a6579e7769937a1d3a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models import Aggregate | |
class Round(Aggregate): | |
""" | |
Solution source for future reference: http://stackoverflow.com/a/34622417/4694834 | |
""" | |
function = 'ROUND' | |
template = '%(function)s(CAST(%(expressions)s AS NUMERIC), {decimals})' | |
name = 'Round' | |
def __init__(self, data, decimals=2): | |
super(Round, self).__init__(data) | |
self.template = self.template.format(decimals=decimals) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment