I have a model with some fields, and I want to add LinkColumn to the details page. I have a working version, but I want to switch to django-tables2
The problem is that the link column does not show any link, just a "-"
Model
class Events(models.Model):
id = models.IntegerField(primary_key=True)
date = models.DateField(null=True, blank=True)
time = models.TimeField(null=True, blank=True)
Table. Here I tried with args=[A('id')]andargs=[A('pk')]
class EventsTable(tables.Table):
time = tables.TemplateColumn("{{value|time:'H:i'}}", verbose_name='Time UTC')
detail_link = tables.LinkColumn('detail', args=[A('id')], verbose_name='Detail')
class Meta:
model = Events
attrs = {"class": "paleblue"}
fields = ("date", "time", "detail_link")
mi url pattern
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^(?P<event_id>\d+)/$', views.detail, name='detail'),
)
and presentation
def index(request):
table = EventsTable(Events.objects.all(), order_by=('-date', '-time'))
RequestConfig(request, paginate={"per_page": PAGE_LIMIT}).configure(table)
return render(request, "db_interface/events.html", {"table": table})
EDIT: Change detail_link to
detail_link = tables.LinkColumn('detail', args=[A('id')], verbose_name='Detail', empty_values=())
now i got a NoReverseMatch exception
Reverse for 'detail' with arguments '(5075,)' and keyword arguments '{}' not found
the number 5075 is the identifier of the first event. I don’t know for what reason the argument is not passed as int?