Ticket #7216: permalink_doc_filled.diff

File permalink_doc_filled.diff, 1.3 KB (added by Masklinn, 16 years ago)

patch with line breaks according to style guide

  • docs/model-api.txt

    diff -r fa8873d3f1ab -r 03d79faa99fd docs/model-api.txt
    a b  
    20052005to display it, without repeating the URL information anywhere. You can still
    20062006use the ``get_absolute_url`` method in templates, as before.
    20072007
     2008In some cases, such as the use of generic views or the re-use of
     2009custom views for multiple models, specifying the view function may
     2010confuse the reverse URL matcher (because multiple patterns point to
     2011the same view).
     2012
     2013For that problem, Django has **named URL patterns**, it's possible to
     2014give a name to a pattern (by replacing the pattern tuple by a call to
     2015the ``url`` function)::
     2016
     2017    from django.conf.urls.defaults import *
     2018
     2019    url(r'^people/(\d+)/$',
     2020        'django.views.generic.list_detail.object_detail',
     2021        name='people_view'),
     2022
     2023and then use that name to perform the reverse URL resolution instead
     2024of the view name::
     2025
     2026    from django.db.models import permalink
     2027
     2028    def get_absolute_url(self):
     2029        return ('people_view', [str(self.id)])
     2030    get_absolute_url = permalink(get_absolute_url)
     2031
     2032More complete informations on named URL patterns are available at
     2033`url dispatch`_.
     2034
     2035.. _url dispatch: ../url_dispatch/#naming-url-patterns
     2036
    20082037Executing custom SQL
    20092038--------------------
    20102039
Back to Top