| 131 | === Checking Permissions in a Template === |
| 132 | |
| 133 | In a template, you can use the tag if_has_perm to check for permissions. The tag has the following syntax: |
| 134 | {% load auth %} |
| 135 | {% if_has_perm [not] (permission codename) [object] %} |
| 136 | ... |
| 137 | {% else %} |
| 138 | ... |
| 139 | {% end_if_has_perm %} |
| 140 | The parameters in square brackets are optional and the normal brackets are required. The else statement is optional. The permission codename should be in the format: app_label.codename. |
| 141 | |
| 142 | === Administration === |
| 143 | |
| 144 | You can set up row level permissions to be created automatically by the admin interface when a user creates an object by using the options: grant_change_row_level_perm and grant_delete_row_level_perm. By default these are turned off. An example: |
| 145 | {{{ |
| 146 | #!python |
| 147 | ... |
| 148 | class Mineral(models.Model): |
| 149 | ... |
| 150 | class Admin: |
| 151 | grant_change_row_level_perm=True |
| 152 | grant_delete_row_level_perm=True |
| 153 | |
| 154 | class Meta: |
| 155 | row_level_permissions = True |
| 156 | ... |
| 157 | }}} |