|
@@ -273,14 +273,13 @@ Custom permissions
|
|
|
To create custom permissions for a given model object, use the ``permissions``
|
|
|
:ref:`model Meta attribute <meta-options>`.
|
|
|
|
|
|
-This example Task model creates three custom permissions, i.e., actions users
|
|
|
-can or cannot do with Task instances, specific to your application::
|
|
|
+This example ``Task`` model creates two custom permissions, i.e., actions users
|
|
|
+can or cannot do with ``Task`` instances, specific to your application::
|
|
|
|
|
|
class Task(models.Model):
|
|
|
...
|
|
|
class Meta:
|
|
|
permissions = (
|
|
|
- ("view_task", "Can see available tasks"),
|
|
|
("change_task_status", "Can change the status of tasks"),
|
|
|
("close_task", "Can remove a task by setting its status as closed"),
|
|
|
)
|
|
@@ -289,11 +288,11 @@ The only thing this does is create those extra permissions when you run
|
|
|
:djadmin:`manage.py migrate <migrate>` (the function that creates permissions
|
|
|
is connected to the :data:`~django.db.models.signals.post_migrate` signal).
|
|
|
Your code is in charge of checking the value of these permissions when a user
|
|
|
-is trying to access the functionality provided by the application (viewing
|
|
|
-tasks, changing the status of tasks, closing tasks.) Continuing the above
|
|
|
-example, the following checks if a user may view tasks::
|
|
|
+is trying to access the functionality provided by the application (changing the
|
|
|
+status of tasks or closing tasks.) Continuing the above example, the following
|
|
|
+checks if a user may close tasks::
|
|
|
|
|
|
- user.has_perm('app.view_task')
|
|
|
+ user.has_perm('app.close_task')
|
|
|
|
|
|
.. _extending-user:
|
|
|
|