mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	magic-removal: Added Manager.__get__ method that forbids access by instances. Also added unit tests. Thanks, rjwittams
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1615 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
		| @@ -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: | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user