Ticket #7003: 7003-permalink-docs.diff
File 7003-permalink-docs.diff, 1012 bytes (added by , 17 years ago) |
---|
-
docs/model-api.txt
2001 2001 Notice that we specify an empty sequence for the second parameter in this case, 2002 2002 because we only want to pass keyword parameters, not positional ones. 2003 2003 2004 You can also use a `named url pattern`_ like this:: 2005 2006 url(r'^people/(\d+)/$', 'people.views.details', name='people_detail') 2007 2008 ...you could reference this using ``permalink()`` as follows:: 2009 2010 def get_absolute_url(self): 2011 return ('people_detail', [str(self.id)]) 2012 get_absolute_url = permalink(get_absolute_url) 2013 2004 2014 In this way, you're tying the model's absolute URL to the view that is used 2005 2015 to display it, without repeating the URL information anywhere. You can still 2006 2016 use the ``get_absolute_url`` method in templates, as before. 2007 2017 2018 .. _named url pattern: ../url_dispatch/#naming-url-patterns 2019 2008 2020 Executing custom SQL 2009 2021 -------------------- 2010 2022