hmarr/mongoengine — pull request #347 by benwah (2011-11-01 20:06:12+00:00)
Title: Add a aggregate_to_python method to BaseField, which allows customization of the data returned by QuerySet.sum and QuerySet.average

I noticed that you cannot easily change the datatype and/or actual data returned by queryset.sum(), this is sometimes useful when writing a BaseField subclass for things like Currency.

I added a "aggregate_to_python" method to BaseField. Any data returned by QuerySet.sum or QuerySet.average is passed to the field's aggregate_to_python method before being returned.

I also added a few lines to mongoengine/tests/queryset.py that ensures the proper behaviour for custom fields with a aggregate_to_python method.