Added support for distinct and db_alias (MongoEngine/mongoengine#59)
This commit is contained in:
		
							
								
								
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							| @@ -115,3 +115,4 @@ that much better: | |||||||
|  * Alexandre González |  * Alexandre González | ||||||
|  * Thomas Steinacher |  * Thomas Steinacher | ||||||
|  * Tommi Komulainen |  * Tommi Komulainen | ||||||
|  |  * Peter Landry | ||||||
|   | |||||||
| @@ -2,8 +2,9 @@ | |||||||
| Changelog | 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) | - Improved support for chained querysets when constraining the same fields (hmarr/mongoengine#554) | ||||||
| - Fixed BinaryField lookup re (MongoEngine/mongoengine#48) | - Fixed BinaryField lookup re (MongoEngine/mongoengine#48) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -34,7 +34,9 @@ class DeReference(object): | |||||||
|  |  | ||||||
|         doc_type = None |         doc_type = None | ||||||
|         if instance and instance._fields: |         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): |             if isinstance(doc_type, ReferenceField): | ||||||
|                 doc_type = doc_type.document_type |                 doc_type = doc_type.document_type | ||||||
|   | |||||||
| @@ -1168,7 +1168,8 @@ class QuerySet(object): | |||||||
|         .. versionchanged:: 0.5 - Fixed handling references |         .. versionchanged:: 0.5 - Fixed handling references | ||||||
|         """ |         """ | ||||||
|         from dereference import DeReference |         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): |     def only(self, *fields): | ||||||
|         """Load only a subset of this document's fields. :: |         """Load only a subset of this document's fields. :: | ||||||
|   | |||||||
| @@ -2299,6 +2299,28 @@ class QuerySetTest(unittest.TestCase): | |||||||
|  |  | ||||||
|         self.assertEquals(Foo.objects.distinct("bar"), [bar]) |         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): |     def test_custom_manager(self): | ||||||
|         """Ensure that custom QuerySetManager instances work as expected. |         """Ensure that custom QuerySetManager instances work as expected. | ||||||
|         """ |         """ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user