1163 | | Linking to admin views |
1164 | | ====================== |
1165 | | |
1166 | | .. versionadded:: 1.1 |
1167 | | |
1168 | | All the admin views use :ref:`named URL patterns <naming-url-patterns>` so it's |
1169 | | easy to link to admin views with ``urlresolvers.reverse`` or the :ttag:`url` |
1170 | | template tag. |
1171 | | |
1172 | | Each model gets its own set of views and its own name using the model's app name |
1173 | | and model name. For example, the "add" view for a ``Choice`` model in a |
1174 | | ``polls`` app would be named ``"admin_polls_choice_add"``. |
1175 | | |
1176 | | All the available views and their names are: |
1177 | | |
1178 | | ============== ====================================== =================== |
1179 | | View View name Parameters |
1180 | | ============== ====================================== =================== |
1181 | | Change list ``"admin_<app>_<model>_changelist"`` None |
1182 | | Add object ``"admin_<app>_<model>_add"`` None |
1183 | | Change object ``"admin_<app>_<model>_change"`` ``object_id`` |
1184 | | Delete object ``"admin_<app>_<model>_delete"`` ``object_id`` |
1185 | | Object history ``"admin_<app>_<model>_history"`` ``object_id`` |
1186 | | ============== ====================================== =================== |
1187 | | |
1188 | | For example, to get the change URL for a particular ``Choice`` object:: |
1189 | | |
1190 | | >>> from django.core import urlresolvers |
1191 | | >>> c = Choice.objects.get(...) |
1192 | | >>> change_url = urlresolvers.reverse('admin_polls_choice_change', (c.id,)) |
1193 | | |
| 1263 | |
| 1264 | .. _admin-reverse-urls: |
| 1265 | |
| 1266 | Reversing Admin URLs |
| 1267 | ==================== |
| 1268 | |
| 1269 | .. versionadded :: 1.1 |
| 1270 | Before Django 1.1 it wasn't possible to reverse admin URLs. In addition |
| 1271 | for this to work you need to be using the new Django 1.1 ``include()`` |
| 1272 | syntax for setting up admin URLs. |
| 1273 | |
| 1274 | The following are the url names, and parameters for ``AdminSite`` urls, all |
| 1275 | url names are prefixed with the ``AdminSite`` instace's name, followed by an |
| 1276 | underscore, so if an ``AdminSite`` was named ``"user_admin"`` it's urls names |
| 1277 | would be prefixed with ``"user_admin_"``, the default ``AdminSite``'s name is |
| 1278 | ``''`` however it's names *do not* have the trailing underscore: |
| 1279 | |
| 1280 | ====================== =============================== ============= |
| 1281 | Page URL name Parameters |
| 1282 | ====================== =============================== ============= |
| 1283 | Index ``admin_index`` |
| 1284 | Logout ``admin_logout`` |
| 1285 | Password change ``admin_password_change`` |
| 1286 | Password change done ``admin_password_change_done`` |
| 1287 | i18n javascript ``admin_jsi18n`` |
| 1288 | Application index page ``admin_app_list`` ``app_label`` |
| 1289 | ====================== =============================== ============= |
| 1290 | |
| 1291 | The remaining urls are for ``ModelAdmin`` instances, these too are all prefixed |
| 1292 | with the ``AdminSite``'s name(with the same caviets as the ``Adminsite``, and |
| 1293 | ``app_label`` and ``model_name`` are the lowercase versions of the |
| 1294 | application's name and the model's name: |
| 1295 | |
| 1296 | ====================== ===================================================== ============= |
| 1297 | Page URL name Parameters |
| 1298 | ====================== ===================================================== ============= |
| 1299 | Changelist ``admin_{{ app_label }}_{{ model_name }}_changelist`` |
| 1300 | Add ``admin_{{ app_label }}_{{ model_name }}_add`` |
| 1301 | History ``admin_{{ app_label }}_{{ model_name }}_history`` ``object_id`` |
| 1302 | Delete ``admin_{{ app_label }}_{{ model_name }}_delete`` ``object_id`` |
| 1303 | Change ``admin_{{ app_label }}_{{ model_name }}_change`` ``object_id`` |
| 1304 | ====================== ===================================================== ============= |
| 1305 | |
| 1306 | For example, to get the change URL for a particular ``Choice`` object, in the |
| 1307 | default admin:: |
| 1308 | |
| 1309 | >>> from django.core import urlresolvers |
| 1310 | >>> c = Choice.objects.get(...) |
| 1311 | >>> change_url = urlresolvers.reverse('admin_polls_choice_change', (c.id,)) |