incorporating dejaMoo: best of breed bull…

Permalink decorator pt. 2

Follow up

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.

Comments (1) § Posted by in on
AddThis Social Bookmark Button

Comments 1

  1. Amirouche B. wrote:

    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.

Tweet Tweet

Stuffs

Thanks for dropping in.

This is the personal website of Cam MacRae. Any opinions expressed here are my entirely own, and have jack to do with my employer.

It's the product of a little elbow grease, the news.ycombinator noprocrast feature, and a healthy dose of Django.

A Django site.

Tags

  1. D (1)
  2. SOA (1)
  3. ajax (2)
  4. apollo (1)
  5. architecture (1)
  6. bemused (1)
  7. blogs (2)
  8. carsales (1)
  9. collaboration (1)
  10. css (1)
  11. django (9)
  12. duels (1)
  13. email (1)
  14. erlang (3)
  15. findability (1)
  16. flex (3)
  17. folksonomies (1)
  18. funny (2)
  19. geek (20)
  20. google (3)
  21. innovation (1)
  22. iphone (1)
  23. javascript (4)
  24. jython (1)
  25. life (5)
  26. lighttpd (1)
  27. lisp (1)
  28. mac (1)
  29. macbook (1)
  30. marketing (1)
  31. open-source (1)
  32. oracle (2)
  33. python (6)
  34. rails (2)
  35. ruby (1)
  36. silverlight (1)
  37. skitch (1)
  38. startups (4)
  39. tech (21)
  40. twitter (1)
  41. usability (1)
  42. web20 (6)
  43. work (3)
  44. yui (2)
ten1000miles.com | Aussie Blogs |  Feed

Creative Commons License This work is licensed under a
Creative Commons Attribution-Share Alike 3.0 Unported License.