[英]how edit and delete rows from django_tables2 and make filter search in up of table and next and previous button
你好,我的朋友们,我使用django_tables2,我展示了我的数据表,一切都很好...我现在想编辑和删除行,并在表的上方进行过滤器搜索..使下一个和上一个...我找不到好有关此的文档,您可以帮我吗? 这是我的表在视图中显示的视图代码谢谢
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>
Django_tables2通过服务器端查询创建视图,并且无法发布数据。 本质上,它所做的是自动创建可以按列标题排序的表。
从文档:
“特征:
任何Iterable都可以是数据源,但其中包括对Django QuerySets的特殊支持。
内置的UI不依赖JavaScript。
支持基于Django模型的自动表生成。
通过子类支持自定义列功能。
分页。
基于列的表排序。
模板标记可实现向HTML的简单呈现。
通用视图混合。”
请参考此处以了解如何使用JavaScript(Ajax)来编辑网页上的数据。 Django-编辑HTML表格行并更新数据库
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.