summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRamiro Morales <cramm0@gmail.com>2011-01-12 23:54:17 +0000
committerRamiro Morales <cramm0@gmail.com>2011-01-12 23:54:17 +0000
commit10ca44ba8daca7258747d5c6bf16e8763a4e6ca6 (patch)
tree3d1fd336bdab5fc0fb0ee5d29dca58dfe88c40c8
parent90be6ca20d607977dec234ec972b77b83955749b (diff)
[1.2.X] Fixed #11124 -- Expanded docstrings of the ModelAdmin has_{change|delete}_permission methods to make it clear they can be overriden to implement per-instance permission checks. Refs #12642.
Backport of [15126] from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15179 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/admin/options.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index bd4b78b9bf..fba3d0c20b 100644
--- a/django/contrib/admin/options.py
+++ b/django/contrib/admin/options.py
@@ -322,17 +322,23 @@ class ModelAdmin(BaseModelAdmin):
media = property(_media)
def has_add_permission(self, request):
- "Returns True if the given request has permission to add an object."
+ """
+ Returns True if the given request has permission to add an object.
+ Can be overriden by the user in subclasses.
+ """
opts = self.opts
return request.user.has_perm(opts.app_label + '.' + opts.get_add_permission())
def has_change_permission(self, request, obj=None):
"""
Returns True if the given request has permission to change the given
- Django model instance.
+ Django model instance, the default implementation doesn't examine the
+ `obj` parameter.
- If `obj` is None, this should return True if the given request has
- permission to change *any* object of the given type.
+ Can be overriden by the user in subclasses. In such case it should
+ return True if the given request has permission to change the `obj`
+ model instance. If `obj` is None, this should return True if the given
+ request has permission to change *any* object of the given type.
"""
opts = self.opts
return request.user.has_perm(opts.app_label + '.' + opts.get_change_permission())
@@ -340,10 +346,13 @@ class ModelAdmin(BaseModelAdmin):
def has_delete_permission(self, request, obj=None):
"""
Returns True if the given request has permission to change the given
- Django model instance.
+ Django model instance, the default implementation doesn't examine the
+ `obj` parameter.
- If `obj` is None, this should return True if the given request has
- permission to delete *any* object of the given type.
+ Can be overriden by the user in subclasses. In such case it should
+ return True if the given request has permission to delete the `obj`
+ model instance. If `obj` is None, this should return True if the given
+ request has permission to delete *any* object of the given type.
"""
opts = self.opts
return request.user.has_perm(opts.app_label + '.' + opts.get_delete_permission())