I'm trying to make the Status booeleanField in the class References change based on the choice input of the action charfield in the class Ecran after the form submission. For example if i select "sortir pour production" in the action field, the Status field automatically changes to False and if i choose the "retour en stock" it changes to true. Also i want to change the false/true of the status booleanfield to show up in the list_references template as simple Indicator icons, red circle for false and green circle for true.
NOTE: the ETAT colum is the Status booleanField in class References.
suivi_ref the form with the action charfield
the form that has the Status booleanfield curerntly i can only change it from here
models.py
class References(models.Model):
Ref = models.CharField(max_length=255, blank=False, null=True)
Designation = models.CharField(max_length=100, blank=False, null=True)
Indice = models.CharField(max_length=100, blank=False, null=True)
Emplacment = models.ForeignKey(place, blank=False, null=True, on_delete=models.SET_NULL)
Num = models.ForeignKey(Rayons, blank=True, null=True, on_delete=models.SET_NULL)
Client = models.ForeignKey(Client, blank=False, null=True, on_delete=models.CASCADE)
Statut = models.BooleanField(default=True)
def __str__(self):
return self.Ref
Action_choice = (
('Sortie pour production', 'Sortie pour production'),
('Retour en stock', 'Retour en stock'),
)
BOOL_CHOICES = ((True, 'OK'), (False, 'NOT OK'))
class Ecran(models.Model):
Nom_de_technicien = models.CharField(max_length=255, blank=True, null=True)
Nom_de_CQ = models.CharField(max_length=255, blank=True, null=True)
Controle_Tension_1 = models.IntegerField(blank=False, null=True)
Controle_Tension_2 = models.IntegerField(blank=False, null=True)
Controle_Tension_3 = models.IntegerField(blank=False, null=True)
Controle_Tension_4 = models.IntegerField(blank=False, null=True)
Controle_Tension_5 = models.IntegerField(blank=False, null=True)
Controle_Visuelle = models.BooleanField(default=False, choices=BOOL_CHOICES)
action = models.CharField(max_length=255, blank=False, null=True, choices=Action_choice)
References = models.ForeignKey(References, on_delete=models.CASCADE, blank=True, null=True)
Date = models.DateTimeField(default=timezone.now, editable=True, )
def __str__(self):
return str(self.References)
views.py
def Ajouter_references(request):
form = ReferencesCreateform(request.POST or None)
if form.is_valid():
form.save()
messages.success(request, 'Ajouté avec succès')
return redirect('/list_references')
context = {
"form": form,
"title": "Ajouter des References",
}
return render(request, "Ajouter_references.html", context)
def suivi_ecran(request):
header = 'Suivi des Ecrans'
form = EcranCreateform(request.POST or None)
queryset = Ecran.objects.all()
if form.is_valid():
form.save()
return redirect('/list_references')
context = {
"header": header,
"queryset": queryset,
"form": form,
}
return render(request, "suivi_ref.html", context)
list_references.html
<form method='POST' action=''>{% csrf_token %}
{{form|crispy}}
<input type="submit" value='Search'/>
<br><br>
<a href="/Ajouter_references"><div class="btn btn-primary mybutton">Ajoute Référence</div></a><br><br>
</form>
<br>
<table class='table'>
<thead>
<tr>
<th>REF</th>
<th>DESIGNATION</th>
<th>INDICE</th>
<th>EMPLACEMENT</th>
<th>NUM</th>
<th>CLIENT</th>
<th>LOCATION</th>
<th>ETAT</th>
<th>SUIVI</th>
<th>SUPPRIMER</th>
</tr>
</thead>
{% for instance in queryset %}
<tr>
<td><a href="{% url 'update_ref' instance.id %}">{{instance.Ref}}</a></td>
<td>{{instance.Designation}}</td>
<td>{{instance.Indice}}</td>
<td>{{instance.Emplacment}}</td>
<td>{{instance.Num}}</td>
<td>{{instance.Client}}</td>
<td><div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
<a href="#">Led 1</a>
<a href="#">Led 2</a>
<a href="#">Led 3</a>
</div>
</div>
</td>
<td>{{instance.Statut}}</td>
<td><a href="{% url 'suivi_ref' %}"><BUTTON>SUIVI L'ECRAN</BUTTON></a></td>
<td><a href="{% url 'delete_ref' instance.id %}"><img src="{% static 'img/del.png' %}"></a></td>
</tr>
{% endfor %}
</table>
</div>
suivie_ref.html
<main role="main" class="container">
<div class="jumbotron">
<h1>{{ header }}</h1>
<form method='POST' action=''>{% csrf_token %}
{{form|crispy}}
<input type="submit" value='Save'/>
</form>
</div>
</main>
Ajouter_references.html
<main role="main" class="container">
<div class="jumbotron">
<h1>{{ title }}</h1>
<form method='POST' id="ReferencesCreateform" data-rayons-url="{% url 'ajax_load_rayons' %}" novalidate >
{% csrf_token %}
{{form|crispy}}
<input type="submit" value='Save'/>
</form>
</div>
