System in Django for student attendance

Asked

Viewed 81 times

-1

I’m trying to learn Django, but I stopped to copy data from the student table to a table that records whether he checked in or checked out at school.

Como ficaria depois de pronto.

Students will wear a badge with CPF in Barcode, the reader transcribes the CPF in the Field and give enter, the system searches the CPF of the Student in the database and brings the information (up to this point I already got). Only that the system must record at the same time in the Check table the following information (Date-time-CPF-NAME-Status), and display the last accesses in the list on the same page.

def busca_alunos(request): dice = {}

if check_busca:

    alunos = Aluno.objects.all()
    alunos = Aluno.objects.filter(cpf=check_busca)

else:
    alunos = Aluno.objects.all()

dados['alunos'] = alunos
return render(request, 'sistema/forms2.html', dados)

As in this same function copy data to the Check table and recognize if you are doing Check-In or Out. I am grateful for your help!

1 answer

0

I got what I wanted, the job was like this:

def Checagem(request):
    dados = {}
    check_busca = request.GET.get('busca', None)
    checagem = Check.objects.all()
    #total = checagem.count()
    #ultimos = total - 10
    checagem = Check.objects.all().order_by('-data')[:10]
    alunos = Aluno.objects.all()

    if check_busca:
        alunos = Aluno.objects.filter(cpf=check_busca)
        check_status = Check.objects.filter(cpf=check_busca).last()
        status = check_status.status
        if status == '0':
            Check.objects.create(data=date, cpf=check_busca, nome=Aluno.objects.get(cpf=check_busca), status='1')
        else:
            Check.objects.create(data=date, cpf=check_busca, nome=Aluno.objects.get(cpf=check_busca), status='0')
        checagem = Check.objects.all().order_by('-data')[:10]
    else:
        pass
    dados['checagem'] = checagem
    dados['alunos'] = alunos

    return render(request, 'sistema/forms.html', dados)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.