如何为django表2中的每条记录设置提交按钮?
我在表单中有一个django_tables2表,这是必需的,因为顶部有一个DeleteSelected按钮。在每一行中,我都需要一个带有“接受”、“拒绝”等操作的提交按钮如何为django表2中的每条记录设置提交按钮?,django,django-tables2,Django,Django Tables2,我在表单中有一个django_tables2表,这是必需的,因为顶部有一个DeleteSelected按钮。在每一行中,我都需要一个带有“接受”、“拒绝”等操作的提交按钮 但我不知道如何识别按下按钮的那一行。我如何才能做到这一点?我找到了一种方法,可以在每一行中添加一个按钮,该按钮的id指向您选择的行: in-app/tables.py import django_tables2 as tables from app.models import MyModel from django.utils
但我不知道如何识别按下按钮的那一行。我如何才能做到这一点?我找到了一种方法,可以在每一行中添加一个按钮,该按钮的id指向您选择的行: in-app/tables.py
import django_tables2 as tables
from app.models import MyModel
from django.utils.safestring import mark_safe
from django.utils.html import escape
class MyColumn(tables.Column):
empty_values = list()
def render(self, value, record):
return mark_safe('<button id="%s" class="btn btn-info">Submit</button>' % escape(record.id))
class MyTable(tables.Table):
submit = MyColumn()
class Meta:
model = MyModel
...
然后我使用Jquery通过检索每个按钮的id来触发我想要的内容
也许这对于您想要做的事情来说有点太简单了,我已经看到其他解决方案使用LinkColumns和Django URL dispatcher可能更有效:
def mypage(request) :
table = MyTable(MyModel.objects.all())
RequestConfig(request,paginate=False).configure(table)
return render(request,'template.html',locals())