make aggregate_sum/average compatible with pymongo 3.x
This commit is contained in:
		| @@ -1261,6 +1261,11 @@ class BaseQuerySet(object): | |||||||
|             { '$match': self._query }, |             { '$match': self._query }, | ||||||
|             { '$group': { '_id': 'sum', 'total': { '$sum': '$' + field } } } |             { '$group': { '_id': 'sum', 'total': { '$sum': '$' + field } } } | ||||||
|         ]) |         ]) | ||||||
|  |         if IS_PYMONGO_3: | ||||||
|  |             result = list(result) | ||||||
|  |             if result: | ||||||
|  |                 return result[0]['total'] | ||||||
|  |         else: | ||||||
|             if result['result']: |             if result['result']: | ||||||
|                 return result['result'][0]['total'] |                 return result['result'][0]['total'] | ||||||
|         return 0 |         return 0 | ||||||
| @@ -1333,6 +1338,11 @@ class BaseQuerySet(object): | |||||||
|             { '$match': self._query }, |             { '$match': self._query }, | ||||||
|             { '$group': { '_id': 'avg', 'total': { '$avg': '$' + field } } } |             { '$group': { '_id': 'avg', 'total': { '$avg': '$' + field } } } | ||||||
|         ]) |         ]) | ||||||
|  |         if IS_PYMONGO_3: | ||||||
|  |             result = list(result) | ||||||
|  |             if result: | ||||||
|  |                 return result[0]['total'] | ||||||
|  |         else: | ||||||
|             if result['result']: |             if result['result']: | ||||||
|                 return result['result'][0]['total'] |                 return result['result'][0]['total'] | ||||||
|         return 0 |         return 0 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user