django-tables2 linkColumn accessor

天大地大妈咪最大 提交于 2019-12-08 04:26:09

问题


I have been using django-tables2 which I like, but i run into some problems

I am trying to make a table in which cells link out to a different table, or an outside link the example in the documentation is :

models.py

class Person(models.Model):
    name = models.CharField(max_length=200)

urls.py

urlpatterns = patterns('',
    url('people/(\d+)/', views.people_detail, name='people_detail')
)

tables.py

from django_tables.utils import A  # alias for Accessor

class PeopleTable(tables.Table):
    name = tables.LinkColumn('people_detail', args=[A('pk')])

I have been trying to use this to no success... What would be the view and template that would go with this example? I think there might be a problem with the url but I am not sure what it is... Can anyone explain: args=[A('pk')]


回答1:


args=[A('pk')] is the primary key of the model from which you're displaying the table. Your example would create a column 'Name' with the cell content <a href="/people/pk"></a> pk would be the primary key (number). The view would be views.people_detail and the template would be whatever you've defined in this view...

Here's the link to the doc: django-tables2 doc

Hope this helps...



来源:https://stackoverflow.com/questions/6157101/django-tables2-linkcolumn-accessor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!