DJANGO - Add/update/delete row in table with backup in sqlite database
Hi everyone :) (sry for my bad english you will have a french accent x) )
I'm stuck in my project because i need to update data already display by model (database objects).
So, i need to add a row, delete a row with confirmation of user, and modify data ( i can already modify data but only into the table (with contenteditable="true" into the td ), it don't save it into the database).
I really need you help to solve this problems, thanks in advance everyone :)
Here my models (i use tableau):
from django.db import models
class Intervenants(models.Model):
name = models.CharField(max_length=3, null=True)
def __str__(self):
return self.name
class tableau(models.Model):
Statut = models.CharField(max_length=1, null=True)
Facturation = models.CharField(max_length=1, null=True)
Commande = models.CharField(max_length=1, null=True)
Num_d_affaire = models.CharField(max_length=100, null=True)
Projet = models.CharField(max_length=120, null=True)
Localisation = models.CharField(max_length=120, null=True)
Descriptif = models.CharField(max_length=120, null=True)
Archi = models.CharField(max_length=120, null=True)
Date_Marqueur = models.CharField(max_length=10, null=True)
BBIO_RT = models.CharField(max_length=10, null=True)
DIAG_FAISA = models.CharField(max_length=10, null=True)
APS = models.CharField(max_length=10, null=True)
APD = models.CharField(max_length=10, null=True)
PRO = models.CharField(max_length=10, null=True)
DCE = models.CharField(max_length=10, null=True)
ACT = models.CharField(max_length=10, null=True)
VISA = models.CharField(max_length=10, null=True)
DET = models.CharField(max_length=10, null=True)
AOR = models.CharField(max_length=10, null=True)
Charge_d_affaire = models.CharField(max_length=3, null=True)
Second = models.CharField(max_length=3, null=True)
Intervenant3 = models.CharField(max_length=3, null=True)
Intervenant4 = models.CharField(max_length=3, null=True)
COSSI = models.CharField(max_length=3, null=True)
Total_interv = models.CharField(max_length=120, null=True)
Tri_par_interv = models.ManyToManyField(Intervenants, null=True)
Date_proche_a_venir = models.CharField(max_length=10, null=True)
Commentaires = models.CharField(max_length=255, null=True)
def __str__(self):
return self.Projet
My bootstrap html table:
<div class="mx-auto col-md-12">
<span class="table-add float-right mb-3 mr-2"><a href="#" class="text-success" ><i class="fas fa-plus fa-2x" aria-hidden="true"></i></a></span>
<div class="scrollable">
<table id="table" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead style="position: sticky;top: 0;background-color: #ffff;">
<tr>
<th class="header" scope="col">Statut</th>
<th class="header" scope="col">A facturer</th>
<th class="header" scope="col">Commande</th>
<th class="header" scope="col">Num d'affaire</th>
<th class="header" scope="col">Nom du projet</th>
<th class="header" scope="col">Localisation</th>
<th class="header" scope="col">Descriptif</th>
<th class="header" scope="col">Archi</th>
<th class="header" scope="col">Date_Marqueur</th>
<th class="header" scope="col">BBIO_RT</th>
<th class="header" scope="col">DIAG_FAISA</th>
<th class="header" scope="col">APS</th>
<th class="header" scope="col">APD</th>
<th class="header" scope="col">PRO</th>
<th class="header" scope="col">DCE</th>
<th class="header" scope="col">ACT</th>
<th class="header" scope="col">VISA</th>
<th class="header" scope="col">DET</th>
<th class="header" scope="col">AOR</th>
<th class="header" scope="col">Chargé d'affaire</th>
<th class="header" scope="col">Second</th>
<th class="header" scope="col">Intervenant3</th>
<th class="header" scope="col">COSSI</th>
<th class="header" scope="col">Total_interv</th>
<th class="header" scope="col">Date proche à venir</th>
<th class="header" scope="col">Commentaires</th>
<th class="header">Remove</th>
</tr>
</thead>
<tbody>
{% for tableau in queryset %}
<tr>
<th scope="row">
{% for cat in tableau.Statut %}
{{ cat }}
{% endfor %}
</th>
<td contenteditable="true">{{ tableau.Facturation }}</td>
<td contenteditable="true">{{ tableau.Commande }}</td>
<td contenteditable="true">{{ tableau.Num_d_affaire }}</td>
<td contenteditable="true">{{ tableau.Projet }}</td>
<td contenteditable="true">{{ tableau.Localisation }}</td>
<td contenteditable="true">{{ tableau.Descriptif }}</td>
<td contenteditable="true">{{ tableau.Archi }}</td>
<td contenteditable="true">{{ tableau.Date_Marqueur }}</td>
<td contenteditable="true">{{ tableau.BBIO_RT }}</td>
<td contenteditable="true">{{ tableau.DIAG_FAISA }}</td>
<td contenteditable="true">{{ tableau.APS }}</td>
<td contenteditable="true">{{ tableau.APD }}</td>
<td contenteditable="true">{{ tableau.PRO }}</td>
<td contenteditable="true">{{ tableau.DCE }}</td>
<td contenteditable="true">{{ tableau.ACT }}</td>
<td contenteditable="true">{{ tableau.VISA }}</td>
<td contenteditable="true">{{ tableau.DET }}</td>
<td contenteditable="true">{{ tableau.AOR }}</td>
<td contenteditable="true">{{ tableau.Charge_d_affaire }}</td>
<td contenteditable="true">{{ tableau.Second }}</td>
<td contenteditable="true">{{ tableau.Intervenant4 }}</td>
<td contenteditable="true">{{ tableau.COSSI }}</td>
<td contenteditable="true">{{ tableau.Total_interv }}</td>
<td contenteditable="true">{{ tableau.Date_proche_a_venir }}</td>
<td contenteditable="true">{{ tableau.Commentaires }}</td>
<td><a class="mx-auto btn btn-danger btn-rounded" href="url:delete_view"><i class="fa fa-trash"></i></a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
My urls.py:
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
from django.urls import path
from core.views import BootstrapFilterView
urlpatterns = [
path('admin/', admin.site.urls),
path('', BootstrapFilterView, name='bootstrap')
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,
document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
And to the end, the views :
from django.shortcuts import render
from core.models import tableau
from django.db.models import Q
def BootstrapFilterView(request):
qs = tableau.objects.all()
Statut_query = request.GET.get('Statut')
Total_interv_query = request.GET.get('Total_interv')
Facturation_query = request.GET.get('Facturation')
# ajouter __icontains aux variables pour enlever le case sensitive
if 'q' in request.GET:
q = request.GET['q']
# qs = tableau.objects.filter(last_name__icontains=q)
multiple_q = Q(Q(Projet__icontains=q) | Q(Localisation__icontains=q) |
Q(Descriptif__icontains=q) | Q(Archi__icontains=q) | Q(Num_d_affaire__icontains=q))
qs = tableau.objects.filter(multiple_q)
if Statut_query != '' and Statut_query != 'Statut...':
qs = qs.filter(Statut__icontains=Statut_query)
if Total_interv_query != '' and Total_interv_query != 'Interv...':
qs = qs.filter(Total_interv__icontains=Total_interv_query)
if Facturation_query == 'on':
qs = qs.filter(Facturation__icontains='F')
context = {
'queryset': qs
}
return render(request, "bootstrap_form.html", context)
ThibaultL