Compare commits
4 Commits
improve-he
...
fix-db-fie
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
999cdfd997 | ||
|
|
2b7417c728 | ||
|
|
3c455cf1c1 | ||
|
|
5135185e31 |
14
README.rst
14
README.rst
@@ -6,15 +6,15 @@ MongoEngine
|
||||
:Author: Harry Marr (http://github.com/hmarr)
|
||||
:Maintainer: Ross Lawley (http://github.com/rozza)
|
||||
|
||||
.. image:: https://secure.travis-ci.org/MongoEngine/mongoengine.png?branch=master
|
||||
:target: http://travis-ci.org/MongoEngine/mongoengine
|
||||
.. image:: https://travis-ci.org/MongoEngine/mongoengine.svg?branch=master
|
||||
:target: https://travis-ci.org/MongoEngine/mongoengine
|
||||
|
||||
.. image:: https://coveralls.io/repos/MongoEngine/mongoengine/badge.png?branch=master
|
||||
:target: https://coveralls.io/r/MongoEngine/mongoengine?branch=master
|
||||
.. image:: https://coveralls.io/repos/github/MongoEngine/mongoengine/badge.svg?branch=master
|
||||
:target: https://coveralls.io/github/MongoEngine/mongoengine?branch=master
|
||||
|
||||
.. image:: https://landscape.io/github/MongoEngine/mongoengine/master/landscape.png
|
||||
:target: https://landscape.io/github/MongoEngine/mongoengine/master
|
||||
:alt: Code Health
|
||||
.. image:: https://landscape.io/github/MongoEngine/mongoengine/master/landscape.svg?style=flat
|
||||
:target: https://landscape.io/github/MongoEngine/mongoengine/master
|
||||
:alt: Code Health
|
||||
|
||||
About
|
||||
=====
|
||||
|
||||
@@ -27,6 +27,7 @@ Changes in 0.10.7
|
||||
- Added support for pickling QuerySet instances. #1397
|
||||
- Fixed connecting to a list of hosts #1389
|
||||
- Fixed a bug where accessing broken references wouldn't raise a DoesNotExist error #1334
|
||||
- Fixed not being able to specify use_db_field=False on ListField(EmbeddedDocumentField) instances #1218
|
||||
- Improvements to the dictionary fields docs # 1383
|
||||
|
||||
Changes in 0.10.6
|
||||
|
||||
@@ -1271,9 +1271,10 @@ class BaseQuerySet(object):
|
||||
:param field: the field to sum over; use dot notation to refer to
|
||||
embedded document fields
|
||||
"""
|
||||
db_field = self._fields_to_dbfields([field]).pop()
|
||||
pipeline = [
|
||||
{'$match': self._query},
|
||||
{'$group': {'_id': 'sum', 'total': {'$sum': '$' + field}}}
|
||||
{'$group': {'_id': 'sum', 'total': {'$sum': '$' + db_field}}}
|
||||
]
|
||||
|
||||
# if we're performing a sum over a list field, we sum up all the
|
||||
@@ -1300,9 +1301,10 @@ class BaseQuerySet(object):
|
||||
:param field: the field to average over; use dot notation to refer to
|
||||
embedded document fields
|
||||
"""
|
||||
db_field = self._fields_to_dbfields([field]).pop()
|
||||
pipeline = [
|
||||
{'$match': self._query},
|
||||
{'$group': {'_id': 'avg', 'total': {'$avg': '$' + field}}}
|
||||
{'$group': {'_id': 'avg', 'total': {'$avg': '$' + db_field}}}
|
||||
]
|
||||
|
||||
# if we're performing an average over a list field, we average out
|
||||
|
||||
@@ -2838,6 +2838,34 @@ class QuerySetTest(unittest.TestCase):
|
||||
sum([a for a in ages if a >= 50])
|
||||
)
|
||||
|
||||
def test_sum_over_db_field(self):
|
||||
"""Ensure that a field mapped to a db field with a different name
|
||||
can be summed over correctly.
|
||||
"""
|
||||
class UserVisit(Document):
|
||||
num_visits = IntField(db_field='visits')
|
||||
|
||||
UserVisit.drop_collection()
|
||||
|
||||
UserVisit.objects.create(num_visits=10)
|
||||
UserVisit.objects.create(num_visits=5)
|
||||
|
||||
self.assertEqual(UserVisit.objects.sum('num_visits'), 15)
|
||||
|
||||
def test_average_over_db_field(self):
|
||||
"""Ensure that a field mapped to a db field with a different name
|
||||
can have its average computed correctly.
|
||||
"""
|
||||
class UserVisit(Document):
|
||||
num_visits = IntField(db_field='visits')
|
||||
|
||||
UserVisit.drop_collection()
|
||||
|
||||
UserVisit.objects.create(num_visits=20)
|
||||
UserVisit.objects.create(num_visits=10)
|
||||
|
||||
self.assertEqual(UserVisit.objects.average('num_visits'), 15)
|
||||
|
||||
def test_embedded_average(self):
|
||||
class Pay(EmbeddedDocument):
|
||||
value = DecimalField()
|
||||
|
||||
Reference in New Issue
Block a user