Permalink
Browse files

POC to address concerns about QuerySet methods overriding Manager met…

  • Loading branch information...
1 parent 2e129ae commit b1d6d2a0cbdb5ad7decc2cf6fc8b8dde960061cf @loic committed Jul 3, 2013
Showing with 9 additions and 6 deletions.
  1. +9 −6 django/db/models/query.py
View
15 django/db/models/query.py
@@ -49,20 +49,24 @@ def get_manager_class(cls, base_cls=None):
"""
Creates a manager class for this QuerySet class.
"""
+
+ if base_cls is None:
+ base_cls = cls.base_manager_class
+ if base_cls is None:
+ from django.db.models.manager import Manager as base_cls
+
def create_method(name):
def manager_copy(self, *args, **kwargs):
return getattr(self.get_queryset(), name)(*args, **kwargs)
return manager_copy
+
new_methods = {}
for name, maybe_copy in cls.__dict__.items():
- if callable(maybe_copy):
+ if name not in base_cls.__dict__ and callable(maybe_copy):
do_copy = getattr(maybe_copy, 'manager', None)
if do_copy or do_copy is None and not name.startswith('_'):
new_methods[name] = create_method(name)
- if base_cls is None:
- base_cls = cls.base_manager_class
- if base_cls is None:
- from django.db.models.manager import Manager as base_cls
+
manager_cls = type(
cls.__name__ + 'Manager',
(base_cls,),
@@ -618,7 +622,6 @@ def all(self):
QuerySet to proxy for a model manager in some cases.
"""
return self._clone()
- all.manager = False
def filter(self, *args, **kwargs):
"""

0 comments on commit b1d6d2a

Please sign in to comment.