Ticket #7216: permalink_doc_filled.diff

File permalink_doc_filled.diff, 1.3 KB (added by masklinn, 7 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.
     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).
     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)::
     2017    from django.conf.urls.defaults import *
     2019    url(r'^people/(\d+)/$',
     2020        'django.views.generic.list_detail.object_detail',
     2021        name='people_view'),
     2023and then use that name to perform the reverse URL resolution instead
     2024of the view name::
     2026    from django.db.models import permalink
     2028    def get_absolute_url(self):
     2029        return ('people_view', [str(self.id)])
     2030    get_absolute_url = permalink(get_absolute_url)
     2032More complete informations on named URL patterns are available at
     2033`url dispatch`_.
     2035.. _url dispatch: ../url_dispatch/#naming-url-patterns
    20082037Executing custom SQL
Back to Top