def update_attendance_in_db_out(present):
    today = datetime.date.today()
    time = datetime.datetime.now()
    for person in present:
        user = User.objects.get(username=person)
        if present[person] == True:
            a = Time(user=user, date=today, time=time, out=True)
            a.save()
def update_attendance_in_db_in(present):
    today = datetime.date.today()
    time = datetime.datetime.now()
    for person in present:
        user = User.objects.get(username=person)
        try:
            qs = Present.objects.get(user=user, date=today)
        except:
            qs = None

        if qs is None:
            if present[person] == True:
                a = Present(user=user, date=today, present=True)
                a.save()
            else:
                a = Present(user=user, date=today, present=False)
                a.save()
        else:
            if present[person] == True:
                qs.present = True
                qs.save(update_fields=['present'])
        if present[person] == True:
            a = Time(user=user, date=today, time=time, out=False)
            a.save()