| 1761 | | decorator. This decorator is passed the view function and any parameters you |
|---|
| 1762 | | would use for accessing this instance directly. Django then works out the |
|---|
| 1763 | | correct full URL path using the URLconf. For example:: |
|---|
| | 1761 | decorator. This decorator is passed the view function, a list of positional |
|---|
| | 1762 | parameters and (optionally) a dictionary of named parameters. Django then |
|---|
| | 1763 | works out the correct full URL path using the URLconf, substituting the |
|---|
| | 1764 | parameters you have given into the URL. For example, if your URLconf |
|---|
| | 1765 | contained a line such as:: |
|---|
| | 1766 | |
|---|
| | 1767 | (r'^/people/(\d+)/$', 'people.views.details'), |
|---|
| | 1768 | |
|---|
| | 1769 | ...your model could have a ``get_absolute_url`` method that looked like this:: |
|---|
| | 1776 | |
|---|
| | 1777 | |
|---|
| | 1778 | Similraly, if you had a URLconf entry that looked like:: |
|---|
| | 1779 | |
|---|
| | 1780 | (r'/archive/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', |
|---|
| | 1781 | archive_view) |
|---|
| | 1782 | |
|---|
| | 1783 | ...you could reference this using ``permalink()`` as follows:: |
|---|
| | 1784 | |
|---|
| | 1785 | def get_absolute_url(self): |
|---|
| | 1786 | return ('archive_view', (), { |
|---|
| | 1787 | 'year': self.created.year, |
|---|
| | 1788 | 'month': self.created.month, |
|---|
| | 1789 | 'day': self.created.day}) |
|---|
| | 1790 | get_absolute_url = permalink(get_absolute_url) |
|---|
| | 1791 | |
|---|
| | 1792 | Notice that we specify an empty sequence for the second argument in this case, |
|---|
| | 1793 | since we're only wanting to pass in some keyword arguments. |
|---|