summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/releases/2.2.txt22
-rw-r--r--docs/topics/auth/default.txt52
2 files changed, 74 insertions, 0 deletions
diff --git a/docs/releases/2.2.txt b/docs/releases/2.2.txt
index d3c8e9abcc..069e098664 100644
--- a/docs/releases/2.2.txt
+++ b/docs/releases/2.2.txt
@@ -439,6 +439,28 @@ Use this instead::
alias = property(operator.attrgetter('base'))
+Permissions for proxy models
+----------------------------
+
+:ref:`Permissions for proxy models <proxy-models-permissions-topic>` are now
+created using the content type of the proxy model rather than the content type
+of the concrete model. A migration will update existing permissions when you
+run :djadmin:`migrate`.
+
+In the admin, the change is transparent for proxy models having the same
+``app_label`` as their concrete model. However, in older versions, users with
+permissions for a proxy model with a *different* ``app_label`` than its
+concrete model couldn't access the model in the admin. That's now fixed, but
+you might want to audit the permissions assignments for such proxy models
+(``[add|view|change|delete]_myproxy``) prior to upgrading to ensure the new
+access is appropriate.
+
+Finally, proxy model permission strings must be updated to use their own
+``app_label``. For example, for ``app.MyProxyModel`` inheriting from
+``other_app.ConcreteModel``, update
+``user.has_perm('other_app.add_myproxymodel')`` to
+``user.has_perm('app.add_myproxymodel')``.
+
Miscellaneous
-------------
diff --git a/docs/topics/auth/default.txt b/docs/topics/auth/default.txt
index 328b9c69bf..640130beb0 100644
--- a/docs/topics/auth/default.txt
+++ b/docs/topics/auth/default.txt
@@ -262,6 +262,20 @@ The permission can then be assigned to a
attribute or to a :class:`~django.contrib.auth.models.Group` via its
``permissions`` attribute.
+.. admonition:: Proxy models need their own content type
+
+ If you want to create :ref:`permissions for a proxy model
+ <proxy-models-permissions-topic>`, pass ``for_concrete_model=False`` to
+ :meth:`.ContentTypeManager.get_for_model` to get the appropriate
+ ``ContentType``::
+
+ content_type = ContentType.objects.get_for_model(BlogPostProxy, for_concrete_model=False)
+
+ .. versionchanged:: 2.2
+
+ In older versions, proxy models use the content type of the concrete
+ model.
+
Permission caching
------------------
@@ -303,6 +317,44 @@ the user from the database. For example::
...
+.. _proxy-models-permissions-topic:
+
+Proxy models
+------------
+
+Proxy models work exactly the same way as concrete models. Permissions are
+created using the own content type of the proxy model. Proxy models don't
+inherit the permissions of the concrete model they subclass::
+
+ class Person(models.Model):
+ class Meta:
+ permissions = (('can_eat_pizzas', 'Can eat pizzas'),)
+
+ class Student(Person):
+ class Meta:
+ proxy = True
+ permissions = (('can_deliver_pizzas', 'Can deliver pizzas'),)
+
+ >>> # Fetch the content type for the proxy model.
+ >>> content_type = ContentType.objects.get_for_model(Student, for_concrete_model=False)
+ >>> student_permissions = Permission.objects.filter(content_type=content_type)
+ >>> [p.codename for p in student_permissions]
+ ['add_student', 'change_student', 'delete_student', 'view_student',
+ 'can_deliver_pizzas']
+ >>> for permission in student_permissions:
+ ... user.user_permissions.add(permission)
+ >>> user.has_perm('app.add_person')
+ False
+ >>> user.has_perm('app.can_eat_pizzas')
+ False
+ >>> user.has_perms(('app.add_student', 'app.can_deliver_pizzas'))
+ True
+
+.. versionchanged:: 2.2
+
+ In older versions, permissions for proxy models use the content type of
+ the concrete model rather than content type of the proxy model.
+
.. _auth-web-requests:
Authentication in Web requests