Support 1-arg queryset managers, but warn about deprecation
This commit is contained in:
parent
6dbc051409
commit
145b0c33fc
@ -724,6 +724,9 @@ class QuerySetManager(object):
|
|||||||
# owner is the document that contains the QuerySetManager
|
# owner is the document that contains the QuerySetManager
|
||||||
queryset = QuerySet(owner, self._collection)
|
queryset = QuerySet(owner, self._collection)
|
||||||
if self._manager_func:
|
if self._manager_func:
|
||||||
|
if self._manager_func.func_code.co_argcount == 1:
|
||||||
|
queryset = self._manager_func(queryset)
|
||||||
|
else:
|
||||||
queryset = self._manager_func(owner, queryset)
|
queryset = self._manager_func(owner, queryset)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
@ -735,4 +738,8 @@ def queryset_manager(func):
|
|||||||
function should return a :class:`~mongoengine.queryset.QuerySet`, probably
|
function should return a :class:`~mongoengine.queryset.QuerySet`, probably
|
||||||
the same one that was passed in, but modified in some way.
|
the same one that was passed in, but modified in some way.
|
||||||
"""
|
"""
|
||||||
|
if func.func_code.co_argcount == 1:
|
||||||
|
import warnings
|
||||||
|
msg = 'Methods decorated with queryset_manager should take 2 arguments'
|
||||||
|
warnings.warn(msg, DeprecationWarning)
|
||||||
return QuerySetManager(func)
|
return QuerySetManager(func)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user