Skip to content

Instantly share code, notes, and snippets.

@Wilfred
Created June 6, 2013 13:44
Show Gist options
  • Select an option

  • Save Wilfred/5721579 to your computer and use it in GitHub Desktop.

Select an option

Save Wilfred/5721579 to your computer and use it in GitHub Desktop.
column with URL to a model for django_tables2
from django.core.urlresolvers import reverse
from django.utils.safestring import mark_safe
import django_tables2 as tables
class ClickableColumn(tables.Column):
"""Renders a link to edit the current object."""
def __init__(self, url_name, *args, **kwargs):
self.url_name = url_name
super(ClickableColumn, self).__init__(*args, **kwargs)
def render(self, value, record):
url = reverse(self.url_name, args=[record.id])
return mark_safe('<a href="%s">%s</a>' % (url, value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment