Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 adrianholovaty authored
Showing with 12 additions and 0 deletions.
  1. +12 −0 django/db/models/__init__.py
12 django/db/models/__init__.py
View
@@ -16,6 +16,18 @@
# Admin stages.
ADD, CHANGE, BOTH = 1, 2, 3
+# Decorator. Takes a function that returns a tuple in this format:
+# (viewname, viewargs, viewkwargs)
+# Returns a function that calls urlresolvers.reverse() on that data, to return
+# the URL for those parameters.
+def permalink(func):
+ from django.core.urlresolvers import reverse
+ def inner(*args, **kwargs):
+ bits = func(*args, **kwargs)
+ viewname = bits[0]
+ return reverse(bits[0], None, *bits[1:2])
+ return inner
+
class LazyDate(object):
"""
Use in limit_choices_to to compare the field to dates calculated at run time
Please sign in to comment.
Something went wrong with that request. Please try again.