'Resolve the value of aggregates returned by the database to
consistent (and reasonable) types.
This is required because of the predisposition of certain backends
to return Decimal and long types when they are not needed.'

def resolve_aggregate(self, value, aggregate, connection):

    if (value is None):
        if aggregate.is_ordinal:
            return 0
        return value
    elif aggregate.is_ordinal:
        return int(value)
    elif aggregate.is_computed:
        return float(value)
    else:
        return self.convert_values(value, aggregate.field, connection)
