Created
June 6, 2013 13:44
-
-
Save Wilfred/5721579 to your computer and use it in GitHub Desktop.
column with URL to a model for django_tables2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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