Added QuerySet.clone() to support copying querysets
This commit is contained in:
parent
69989365c7
commit
53d66b7267
@ -294,6 +294,20 @@ class QuerySet(object):
|
|||||||
self._limit = None
|
self._limit = None
|
||||||
self._skip = None
|
self._skip = None
|
||||||
|
|
||||||
|
def clone(self):
|
||||||
|
"""Creates a copy of the current :class:`~mongoengine.queryset.QuerySet`"""
|
||||||
|
c = self.__class__(self._document, self._collection_obj)
|
||||||
|
|
||||||
|
copy_props = ('_initial_query', '_query_obj', '_where_clause',
|
||||||
|
'_loaded_fields', '_ordering', '_snapshot',
|
||||||
|
'_timeout', '_limit', '_skip')
|
||||||
|
|
||||||
|
for prop in copy_props:
|
||||||
|
val = getattr(self, prop)
|
||||||
|
setattr(c, prop, copy.deepcopy(val))
|
||||||
|
|
||||||
|
return c
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _query(self):
|
def _query(self):
|
||||||
if self._mongo_query is None:
|
if self._mongo_query is None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user