Ticket #7216: permalink_doc.diff

File permalink_doc.diff, 1.3 KB (added by Masklinn, 10 years ago)
  • docs/model-api.txt

    diff -r 3762db44f8cd 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 custom views for multiple models, specifying the view function may confuse the reverse URL matcher (because multiple patterns point to the same view).
     2010For that problem, Django has **named URL patterns**, it's possible to give a name to a pattern (by replacing the pattern tuple by a call to the ``url`` function)::
     2012    from django.conf.urls.defaults import *
     2014    url(r'^people/(\d+)/$', 'django.views.generic.list_detail.object_detail', name='people_view'),
     2016and then use that name to perform the reverse URL resolution instead of the view name::
     2018    from django.db.models import permalink
     2020    def get_absolute_url(self):
     2021        return ('people_view', [str(self.id)])
     2022    get_absolute_url = permalink(get_absolute_url)
     2024More complete informations on named URL patterns are available at `url dispatch`_.
     2026.. _url dispatch: ../url_dispatch/#naming-url-patterns
    20082028Executing custom SQL
Back to Top