Code

Ticket #7216: permalink_doc_filled.diff

File permalink_doc_filled.diff, 1.3 KB (added by masklinn, 6 years ago)

patch with line breaks according to style guide

Line 
1diff -r fa8873d3f1ab -r 03d79faa99fd docs/model-api.txt
2--- a/docs/model-api.txt        Wed May 14 09:21:37 2008 +0000
3+++ b/docs/model-api.txt        Wed May 14 16:21:08 2008 +0200
4@@ -2005,6 +2005,35 @@
5 to display it, without repeating the URL information anywhere. You can still
6 use the ``get_absolute_url`` method in templates, as before.
7 
8+In some cases, such as the use of generic views or the re-use of
9+custom views for multiple models, specifying the view function may
10+confuse the reverse URL matcher (because multiple patterns point to
11+the same view).
12+
13+For that problem, Django has **named URL patterns**, it's possible to
14+give a name to a pattern (by replacing the pattern tuple by a call to
15+the ``url`` function)::
16+
17+    from django.conf.urls.defaults import *
18+
19+    url(r'^people/(\d+)/$',
20+        'django.views.generic.list_detail.object_detail',
21+        name='people_view'),
22+
23+and then use that name to perform the reverse URL resolution instead
24+of the view name::
25+
26+    from django.db.models import permalink
27+
28+    def get_absolute_url(self):
29+        return ('people_view', [str(self.id)])
30+    get_absolute_url = permalink(get_absolute_url)
31+
32+More complete informations on named URL patterns are available at
33+`url dispatch`_.
34+
35+.. _url dispatch: ../url_dispatch/#naming-url-patterns
36+
37 Executing custom SQL
38 --------------------
39