Hello, I am installing a parking system where the check is done automatically, at the time of registration it picks up the current time and date, and when I click on update it has 3 buttons, save, delete and checkout, and I wanted it when I clicked on the checkout it happened to the checkout field the current checkout date and time, and you can either reload the same refresh page to show the updated field, or just insert and then I can save it normally, but I can not do either
Model.py
PAGO_CHOICES = (
('Não', 'Não Pago'),
('Sim', 'Pago')
)
class MovRotativo(models.Model):
checkin = models.DateTimeField(auto_now=True, blank=False, null=False,)
checkout = models.DateTimeField(default=None, null=True, blank=True)
email = models.EmailField(blank=False)
placa = models.CharField(max_length=7, blank=False)
modelo = models.CharField(max_length=15, blank=False)
valor_hora = models.DecimalField(
max_digits=5, decimal_places=2, null=False, blank=False)
pago = models.CharField(max_length=15, choices=PAGO_CHOICES)
views.py
@login_required
def movrotativos_update(request, id):
data = {}
mov_rotativo = MovRotativo.objects.get(id=id)
form = MovRotativoForm(request.POST or None, instance=mov_rotativo)
data['mov_rotativo'] = mov_rotativo
data['form'] = form
if request.method == 'POST':
if form.is_valid():
form.save()
return redirect('core_lista_movrotativos')
else:
return render(request, 'core/update_movrotativos.html', data)
html.
{%extends 'basenew.html' %}
{% load bootstrap %}
{% block main %}
<main role="main" class="col-md-12 ml-sm-auto col-lg-10 px-50">
<br>
<br><br>
<div class="row">
<div class="col">
<h2>UpDating MovRotativos: {{ mov_rotativo}}</h2>
<form action="{% url 'core_movrotativos_update' mov_rotativo.id %}"
method="POST">
{% csrf_token %}
{{form|bootstrap}}
<table class="table table-bordered sortable" >
<thead class="p-3 mb-2 bg-primary text-white">
<tr>
<th scope="col">Horas</th>
<th scope="col">Pagar</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="" style="color:black">
{{mov_rotativo.horas_total}}</a></td>
<td><a href="" style="color:black">
{{mov_rotativo.total}}</a></td>
</tr>