Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added django.db.models.permalink decorator, which decorates a functio…

…n that returns a viewname, viewargs and viewkwargs. The decorator returns the result of a reverse URL lookup on those parameters. Documentation is forthcoming.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3472 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1707f79b74b32ad20ee36e03818688ee4dc02d21 1 parent 3770dbd
Adrian Holovaty authored July 28, 2006

Showing 1 changed file with 12 additions and 0 deletions. Show diff stats Hide diff stats

  1. 12  django/db/models/__init__.py
12  django/db/models/__init__.py
@@ -16,6 +16,18 @@
16 16
 # Admin stages.
17 17
 ADD, CHANGE, BOTH = 1, 2, 3
18 18
 
  19
+# Decorator. Takes a function that returns a tuple in this format:
  20
+#     (viewname, viewargs, viewkwargs)
  21
+# Returns a function that calls urlresolvers.reverse() on that data, to return
  22
+# the URL for those parameters.
  23
+def permalink(func):
  24
+    from django.core.urlresolvers import reverse
  25
+    def inner(*args, **kwargs):
  26
+        bits = func(*args, **kwargs)
  27
+        viewname = bits[0]
  28
+        return reverse(bits[0], None, *bits[1:2])
  29
+    return inner
  30
+
19 31
 class LazyDate(object):
20 32
     """
21 33
     Use in limit_choices_to to compare the field to dates calculated at run time

0 notes on commit 1707f79

Please sign in to comment.
Something went wrong with that request. Please try again.