更新结帐日志而无需离开页面

时间:2018-12-05 16:50:27

标签: python django

我的签入是自动的,我的签出是None,我想要页面更新html内的注册,我选中了一个按钮,当我单击它时,签出已更新为当前时间,已经填写了表格,无需离开页面

我尝试过,但我不会犯错

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>
                  
                    </tbody>
                  
                                 
            </table>
                        <button type="submit" class="btn btn- 
   primary">Salvar</button>
                        <form action="{%  url 'core_movrotativos_checkout' 
    mov_rotativo.id  %}" method="POST">
                        <button type="submit" class="btn btn- 
   primary">Checkout</button>
                        </form>
            <a href="{% url 'core_movrotativos_delete' mov_rotativo.id%}" 
     class="btn btn-danger">Delete</a>
            
          
            

        </form>

       </div>
    </div>
    </main>
    {% endblock %}

0 个答案:

没有答案