Python 如何在访问django表后将其内的按钮更改为文本
这是我使用Django的第一个项目,也是我第一次使用Django-Tables2。 我有一个Django表,有三列,最后一列包含每行的add按钮,单击该按钮会将我带到另一个页面,在那里我可以选择选项。提交选项时,映射将保存在数据库中,用户将再次重定向到表页面。这里我想把“添加”按钮改为“完成”Python 如何在访问django表后将其内的按钮更改为文本,python,django,django-forms,django-tables2,Python,Django,Django Forms,Django Tables2,这是我使用Django的第一个项目,也是我第一次使用Django-Tables2。 我有一个Django表,有三列,最后一列包含每行的add按钮,单击该按钮会将我带到另一个页面,在那里我可以选择选项。提交选项时,映射将保存在数据库中,用户将再次重定向到表页面。这里我想把“添加”按钮改为“完成” {%csrf_令牌%} {{form.as_p}} {%load render_Tables from django_Tables 2%} {%block content%} {%render_ta
{%csrf_令牌%}
{{form.as_p}}
{%load render_Tables from django_Tables 2%}
{%block content%}
{%render_table%}
{%endblock%}
URL模式=[
路径(“”,views.countries_view,name='index'),
路径('/',views.edit_item,name=“edit_item”),
路径('table/',views.secondpage,name=“secondpage”),
]
所以,我找到了解决方案
class CustomTemplateColumn(tables.TemplateColumn):
def render(self, record, table, value, bound_column, **kwargs):
if record.status == "done":
return 'DONE'
return super(CustomTemplateColumn, self).render(record, table, value, bound_column, **kwargs)
class CustomTemplateColumnEdit(tables.TemplateColumn):
def render(self, record, table, value, bound_column, **kwargs):
if record.edit_status == "done":
return 'DONE'
return super(CustomTemplateColumnEdit, self).render(record, table, value, bound_column, **kwargs)
class PersonTable(tables.Table):
T1 = '<a href="edit/businessactivity/{{record.id}}/">EDIT</a>'
T2 = '<a href="edit/{{ record.id }}">ADD</a>'
Edit_Regulation = CustomTemplateColumnEdit(T1)
Process = CustomTemplateColumn(T2)
class Meta:
model = BAReg
fields =['businessdefinition_a', 'regulation']
template_name = 'django_tables2/semantic.html'
class CustomTemplateColumn(tables.TemplateColumn):
def呈现(自身、记录、表格、值、绑定列,**kwargs):
如果record.status==“完成”:
返回“完成”
return super(CustomTemplateColumn,self).render(记录,表,值,绑定列,**kwargs)
类CustomTemplateColumnEdit(tables.TemplateColumn):
def呈现(自身、记录、表格、值、绑定列,**kwargs):
如果record.edit_status==“完成”:
返回“完成”
return super(CustomTemplateColumnEdit,self).render(记录,表,值,绑定列,**kwargs)
类PersonTable(tables.Table):
T1=“”
T2=''
编辑规则=CustomTemplateColumnEdit(T1)
流程=CustomTemplateColumn(T2)
类元:
模型=巴雷格
字段=['businessdefinition_a','regulation']
template_name='django_tables2/semantic.html'
class PersonTable(tables.Table):
Process = tables.LinkColumn('edit_item',text='Add Process', args=[A('pk')])
class Meta:
model = BAReg
template_name = 'django_tables2/bootstrap4.html'
<form method='post' action=''>
{% csrf_token %}
{{ form.as_p }}
<input type='submit' value='submit'>
</form>
{% load render_table from django_tables2 %}
{% block content %}
<!-- <form method="POST"> -->
{% render_table table %}
<!-- {{ form.as_p }} -->
<!-- <button type="submit" style="margin-left: 680px">Submit</button>
</form> -->
{% endblock %}
urlpatterns = [
path('', views.countries_view, name='index'),
path('<int:pk>/', views.edit_item, name="edit_item"),
path('table/',views.secondpage, name ="secondpage"),
]
class CustomTemplateColumn(tables.TemplateColumn):
def render(self, record, table, value, bound_column, **kwargs):
if record.status == "done":
return 'DONE'
return super(CustomTemplateColumn, self).render(record, table, value, bound_column, **kwargs)
class CustomTemplateColumnEdit(tables.TemplateColumn):
def render(self, record, table, value, bound_column, **kwargs):
if record.edit_status == "done":
return 'DONE'
return super(CustomTemplateColumnEdit, self).render(record, table, value, bound_column, **kwargs)
class PersonTable(tables.Table):
T1 = '<a href="edit/businessactivity/{{record.id}}/">EDIT</a>'
T2 = '<a href="edit/{{ record.id }}">ADD</a>'
Edit_Regulation = CustomTemplateColumnEdit(T1)
Process = CustomTemplateColumn(T2)
class Meta:
model = BAReg
fields =['businessdefinition_a', 'regulation']
template_name = 'django_tables2/semantic.html'