The linkcolumn about django-tables2
Asked Answered
P

1

7

I use django-tables2 to show some data in page,and now I want to make the cell link to some url,but the link url such as :

url(r'^(?P\w+)/(?P\d+)/$', 'pool.views.pooldatestock', name="pool_date_stock"),

and I read the documents of django-tables2,but I can't find some excample about this problem.

the tables show in the page's url just like:http://127.0.0.1:8000/pool/20111222/

I try to write this in my tables.py :

class PoolTable(tables.Table):
    number = tables.LinkColumn('pool.views.pooldatestock', args=[A('number')])
    date = tables.Column()

and then I try to write:

class PoolTable(tables.Table):
    number=tables.LinkColumn('pool.views.pooldatestock',
                             args=[A('date')],
                             kwargs=A('number')])
    date = tables.Column()

but it's error too...

somebody can tell me how to solve this problem?or should I create my own table view, without django-tables.

Thanks.and Merry Christmas:)

Portsmouth answered 23/12, 2011 at 7:54 Comment(0)
O
7

It makes no sense for the kwargs parameter to be given a list, it should be given a dict. However as your URL doesn't used named groups, it doesn't need keyword arguments anyway. Just put both URL parameters in the args parameter:

class PoolTable(tables.Table):
    number = tables.LinkColumn('pool.views.pooldatestock',
                               args=[A('date'), A('number')])
    date = tables.Column()
Outmost answered 23/12, 2011 at 9:45 Comment(2)
Thanks bradley.ayers,I got it.I don't understand the args and kwargs before.:)Merry ChristmasPortsmouth
Well LinkColumn tries to follow the same API as the django.core.urlresolvers.reverse() function. Have a look at the docs for that if you want to understand the arguments.Outmost

© 2022 - 2024 — McMap. All rights reserved.