Since writing briefly about Django's permalink decorator I've had quite a few emails regarding the use of the permalink decorator and generic views.
Here is what works for me...
I often have the following urlconf in urls.py:
urlpatterns = patterns('django.views.generic.date_based',
(r'^(?P<year>d{4})/(?P<month>d{1,2})/(?P<day>w{1,2})/(?P<slug>[-w]+)/$',
'object_detail', dict(info_dict, month_format='%m')),
)
And the corresponding get_absolute_url method cut straight from my class looks like this:
@permalink
def get_absolute_url(self):
"""
return
absolute url of this object
"""
#pylint: disable-msg=E1101
return ('django.views.generic.date_based.object_detail', None, {
'year': self.create_date.year,
'month': self.create_date.strftime('%m'),
'day': self.create_date.strftime('%d'),
'slug': self.slug})
This is already well documented here and here, but I hope this extra example helps.
Note: For completeness, I use Eclipse with Emacs key bindings and the Pydev plug-in with pylint activated - hence the pylint ignore directive.

Feed
Comments 1
You should also have a word about url method and the {% url myobject %} no. It's only in trunk but so do permalink no ?
Posted August 22, 2007 at 8:55 a.m. ¶Comments are now closed.