【发布时间】:2019-12-29 23:46:15
【问题描述】:
你好,我的朋友们,我使用 django_tables2,我显示了我的数据表,一切正常……我现在想编辑和删除行,并使过滤器在表中搜索……使下一个和 pervious……我愿意没有找到关于这个的好文档,所以你能帮助我吗?这是在视图中显示的我的表的视图代码 谢谢
def Immoblist(request):
table = ImmobTable(Immob.objects.all())
table.paginate(page=request.GET.get('page', 1), per_page=25)
RequestConfig(request).configure(table)
return render(request,"immob_list.html", {'table': table})
#this is tables.py
import django_tables2 as tables
from .models import Immob
from django_tables2 import SingleTableView
from django_tables2.views import SingleTableMixin
class ImmobTable(tables.Table):
id = tables.Column(verbose_name= 'ID')
immo_code=tables.Column(verbose_name='Code')
immo_desig=tables.Column(verbose_name='Désignation')
immo_qte=tables.Column(verbose_name='Quantité ')
immo_datemes=tables.Column(verbose_name='Date mes ')
immo_cptimmob=tables.Column(verbose_name='Compte comptable ')
immo_dureevie=tables.Column(verbose_name='Durée de vie ')
immo_origine=tables.Column(verbose_name='Origine ')
immo_fournisseur=tables.Column(verbose_name='Fournisseur ')
immo_nufact=tables.Column(verbose_name='N° facture ')
immo_datefact=tables.Column(verbose_name='Date facture ')
immo_valht=tables.Column(verbose_name='Valeur HT ')
immo_monaie=tables.Column(verbose_name='Monnaie ')
immo_tauxcvt=tables.Column(verbose_name='Taux de conversion ')
immo_tauxctrval=tables.Column(verbose_name='Contre valeur/DA ')
immo_frais=tables.Column(verbose_name="Frais d'approche ")
immo_coutacq=tables.Column(verbose_name="Cout total d'acquisition ")
immo_refcmde=tables.Column(verbose_name='Référence commande ')
immo_datecmde=tables.Column(verbose_name='Date commande ')
immo_journee=tables.Column(verbose_name='Numéro de journée ')
immo_cptanal=tables.Column(verbose_name='Compte Analytique')
immo_local=tables.Column(verbose_name='Localisation ')
immo_mode_amort=tables.Column(verbose_name="Méthode d'amortissement ")
immo_code_r=tables.Column(verbose_name="Dernier plan d'amortissement ")
immo_val_amort=tables.Column(verbose_name="Valeur à amortir ")
immo_status=tables.Column(verbose_name='Code status')
immo_code_bar=tables.Column(verbose_name='Code à barre ')
service=tables.Column(verbose_name='Service ')
cni=tables.Column(verbose_name='Code cni ')
class Meta:
model = Immob
attrs = {'class': 'table table-sm'}
template_name = 'django_tables2/bootstrap4.html'
class ImmobList(SingleTableView):
model = Immob
table_class = ImmobTable
#la page immob_list. HTML
<!doctype html>
{% load render_table from django_tables2 %}
{% load static%}
<html>
<table class="table table-bordered">
<head>
<title>Liste des Immobilisations</title>
<link rel="stylesheet" href="{% static '/css/bootstrap.min.css' %}" />
</head>
<body>
<div style="overflow-y: auto; height:10px; ">
{% block content %}
{% render_table table %}
{% endblock content %}
</div>
</body>
</table>
</html>
【问题讨论】:
标签: python django django-forms django-tables2