Django Tables adding a LinkColumn / NoReverseMatch Error

1.3k views Asked by At

I have a model with some fields and I want to add a LinkColumn to a detail page. I have a working version, but I want to move to django-tables2

The problem is that the link column doesnt show any link, just a "-"

The 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)

The Table. Here I tried with args=[A('id')] and args=[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 is

urlpatterns = patterns('',
    url(r'^$', views.index, name='index'),
    url(r'^(?P<event_id>\d+)/$', views.detail, name='detail'),
)

and the view

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: Changing the 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 id of the first event. I dont know if for any reason is not passing the argument as an int ?

1

There are 1 answers

6
SunnySydeUp On BEST ANSWER

Try:

detail_link = tables.LinkColumn('detail', args=[A('id')], verbose_name='Detail', empty_values=())

According to the docs, render methods are only called if the value for a cell is determined to be not an empty value. Since the Event model does not have a detail_link field, there's no value given to it.