我正在尝试建立用户删除链接。我用这个djnago-tables2。 在应该有删除链接的地方有水平线。
class UsersListTable(BaseTable):
user = tables.Column(
order_by=('user__last_name', 'user__first_name'),
accessor='user.get_full_name',
verbose_name=_('Employee')
)
delete_link = tables.LinkColumn('deleteUser', args=[A('pk')])
class Meta(BaseTable.Meta):
model = MyModel
fields = ('country', 'name', 'delete_link')
empty_text = _('No users')
我的观点:
class DeleteUser(DeleteView):
model = MyModel
template_name = "templates/list_of_users.html"
success_url = reverse_lazy('myapp:base')
def get_object(self, queryset=None):
obj = super(DeleteUser, self).get_object()
return obj
def get_success_url(self):
return reverse('base')
我的网址:
url(r'^delete/(?P<pk>\d+)/$', views.DeleteUser.as_view(), name='deleteUser'),
答案 0 :(得分:0)
您可以使用TemplateColumn:
#tables.py:
TEMPLATE = '''
<a href="{% url 'deleteUser' record.pk %}">delete</a>
'''
class UsersListTable...
....
delete_link = tables.TemplateColumn(TEMPLATE)
另一个选项是render_FOO metod (https://django-tables2.readthedocs.org/en/latestindex.html?highlight=render_foo)