Exception Value: ['“Sunday” value has an invalid date format. It must be in YYYY-MM-DD format.']

I'm trying to save theAttendance mode, but I'm getting an error. I can't figureout what it is.

Error is ['“Sunday” value has an invalid date format. It must be in YYYY-MM-DD format.']

Here is my models.py

from django.db import models
from employee.models import Employee

# Create your models here.

class Attendance(models.Model):
    employee = models.ForeignKey(Employee, on_delete=models.CASCADE)
    date = models.DateField()
    day = models.CharField(max_length=10)
    in_time = models.CharField(max_length=5)
    out_time = models.CharField(max_length=5)

Here is my views.py

from django.shortcuts import render,redirect
from django.views.generic import View
from django.http import JsonResponse
from employee.models import Employee
from .models import Attendance

# Create your views here.

class MarkAttendanceMainView(View):
    def get(self,request):
        return render(request,"mark_attendance.html")
    def post(self,request):
        attendance_time_in =  []
        attendance_time_out = []
        attendance_date = []
        attendance_day = []
        emp_id = request.POST['attendance_emp_id']
        emp = Employee.objects.filter(emp_id=emp_id)
        for id in request.POST:
            if "in" in id.split("_"):
            elif "out" in id.split("_"):
            elif "date" in id.split("_"):
            elif "day" in id.split("_"):
        i = 0
        while i < len(attendance_time_in):
            date = request.POST[attendance_date[i]]
            day = request.POST[attendance_day[i]]
            time_in = request.POST[attendance_time_in[i]]
            time_out = request.POST[attendance_time_out[i]]
            i +=1
            print(emp, date, day, time_in, time_out)
            attendance = Attendance(emp,date,day,time_in,time_out)

        return redirect('mark_attendance_main_view')

In here as i haven't specified an primary key, django has automatically created one. So when saving the Attendance model 'id' comes first Attendance(id,employee..) So i have to specifically mention the fields like this Attendance(employee=emp, date=date, day=day, ...)

Back to Top