【问题标题】:how edit and delete rows from django_tables2 and make filter search in up of table and next and previous button如何从 django_tables2 编辑和删除行并在表和下一个和上一个按钮中进行过滤搜索
【发布时间】: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


    【解决方案1】:

    Django_tables2 通过服务器端查询创建视图,并且没有发布数据的能力。本质上,它的作用是自动创建可以按列标题排序的表。

    来自文档:

    “特点:

    任何可迭代对象都可以是数据源,但包括对 Django QuerySets 的特殊支持。

    内置 UI 不依赖于 JavaScript。

    支持基于 Django 模型的自动表生成。

    通过子类化支持自定义列功能。

    分页。

    基于列的表格排序。

    模板标签可以实现简单的 HTML 渲染。

    通用视图混合。”

    请参阅此处了解如何使用 JavaScript (Ajax) 来编辑网页上的数据。 Django - edit HTML table rows and update database

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-30
      • 1970-01-01
      • 2017-09-24
      • 2011-03-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多