diff --git a/django/core/meta/__init__.py b/django/core/meta/__init__.py index 5d4a4f811c..a2a9065e42 100644 --- a/django/core/meta/__init__.py +++ b/django/core/meta/__init__.py @@ -1194,10 +1194,15 @@ class Model: __set_many_to_many_objects.alters_data = True -class Manager: +class Manager(object): def __init__(self, model_class): self.klass = model_class + def __get__(self, instance, type=None): + if instance != None: + raise AttributeError, "Manager isn't accessible via %s instances" % self.klass.__name__ + return self + def _prepare(self): # Creates some methods once self.klass._meta has been populated. if self.klass._meta.get_latest_by: diff --git a/tests/modeltests/basic/models.py b/tests/modeltests/basic/models.py index 92d8a1b5ac..0bbd60dd58 100644 --- a/tests/modeltests/basic/models.py +++ b/tests/modeltests/basic/models.py @@ -180,6 +180,18 @@ False >>> Article.objects.get_pub_date_list('day', order='DESC') [datetime.datetime(2005, 7, 31, 0, 0), datetime.datetime(2005, 7, 30, 0, 0), datetime.datetime(2005, 7, 29, 0, 0), datetime.datetime(2005, 7, 28, 0, 0)] +# An Article instance doesn't have access to the "objects" attribute. +# That is only available as a class method. +>>> a7.objects.get_list() +Traceback (most recent call last): + ... +AttributeError: Manager isn't accessible via Article instances + +>>> a7.objects +Traceback (most recent call last): + ... +AttributeError: Manager isn't accessible via Article instances + """ from django.conf import settings