Added support for distinct and db_alias (MongoEngine/mongoengine#59)
This commit is contained in:
parent
95b1783834
commit
475488b9f2
3
AUTHORS
3
AUTHORS
@ -114,4 +114,5 @@ that much better:
|
||||
* Jaime Irurzun
|
||||
* Alexandre González
|
||||
* Thomas Steinacher
|
||||
* Tommi Komulainen
|
||||
* Tommi Komulainen
|
||||
* Peter Landry
|
||||
|
@ -2,8 +2,9 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
Changes in 0.6.X
|
||||
================
|
||||
Changes in 0.6.20
|
||||
=================
|
||||
- Added support for distinct and db_alias (MongoEngine/mongoengine#59)
|
||||
- Improved support for chained querysets when constraining the same fields (hmarr/mongoengine#554)
|
||||
- Fixed BinaryField lookup re (MongoEngine/mongoengine#48)
|
||||
|
||||
|
@ -34,7 +34,9 @@ class DeReference(object):
|
||||
|
||||
doc_type = None
|
||||
if instance and instance._fields:
|
||||
doc_type = instance._fields[name].field
|
||||
doc_type = instance._fields[name]
|
||||
if hasattr(doc_type, 'field'):
|
||||
doc_type = doc_type.field
|
||||
|
||||
if isinstance(doc_type, ReferenceField):
|
||||
doc_type = doc_type.document_type
|
||||
|
@ -1168,7 +1168,8 @@ class QuerySet(object):
|
||||
.. versionchanged:: 0.5 - Fixed handling references
|
||||
"""
|
||||
from dereference import DeReference
|
||||
return DeReference()(self._cursor.distinct(field), 1)
|
||||
return DeReference()(self._cursor.distinct(field), 1,
|
||||
name=field, instance=self._document)
|
||||
|
||||
def only(self, *fields):
|
||||
"""Load only a subset of this document's fields. ::
|
||||
|
@ -871,7 +871,7 @@ class QuerySetTest(unittest.TestCase):
|
||||
published_date__lt=datetime(2010, 1, 7, 0, 0 ,0))
|
||||
self.assertEqual(published_posts.count(), 2)
|
||||
|
||||
|
||||
|
||||
blog_posts = BlogPost.objects
|
||||
blog_posts = blog_posts.filter(blog__in=[blog_1, blog_2])
|
||||
blog_posts = blog_posts.filter(blog=blog_3)
|
||||
@ -2299,6 +2299,28 @@ class QuerySetTest(unittest.TestCase):
|
||||
|
||||
self.assertEquals(Foo.objects.distinct("bar"), [bar])
|
||||
|
||||
def test_distinct_handles_references_to_alias(self):
|
||||
register_connection('testdb', 'mongoenginetest2')
|
||||
|
||||
class Foo(Document):
|
||||
bar = ReferenceField("Bar")
|
||||
meta = {'db_alias': 'testdb'}
|
||||
|
||||
class Bar(Document):
|
||||
text = StringField()
|
||||
meta = {'db_alias': 'testdb'}
|
||||
|
||||
Bar.drop_collection()
|
||||
Foo.drop_collection()
|
||||
|
||||
bar = Bar(text="hi")
|
||||
bar.save()
|
||||
|
||||
foo = Foo(bar=bar)
|
||||
foo.save()
|
||||
|
||||
self.assertEquals(Foo.objects.distinct("bar"), [bar])
|
||||
|
||||
def test_custom_manager(self):
|
||||
"""Ensure that custom QuerySetManager instances work as expected.
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user