Date being in correct format, ORM says has to be in YYYY-MM-DD format

print("data['attachments']['start'] =", data['attachments']['start'])    # 2023-10-18
formatted_start_date = data['attachments']['start']
print("formatted_start_date =",formatted_start_date) # 2023-10-18

soDict = {
        'so_start_date': formatted_start_date,
        'so_end_date': formatted_end_date,
}

print("soDict =", soDict)
so = ServiceOrder(**soDict)
so.save()

But I get :

django.core.exceptions.ValidationError: ['β€œβ€ value has an invalid date format. It must be in YYYY-MM-DD format.']

The model is like this :

class ServiceOrder(models.Model):
    so_start_date = models.DateField(blank=True, null=True)
    so_end_date = models.DateField(blank=True, null=True)

Unfortunately, your print statement is not necessarily showing you the actual format of the data being printed. If data['attachments']['start'] is an object and not a string, what you are looking at is the output of the __str__ method of that object. You need to take a closer look at what that data is.

Hey there, i want to just give a tip on this sintax. It really helps when debugging.

This can be shortened with the f-string sintax, and will provide the same output.

print(f"{data['attachments']['start']=}")
1 Like

I solved this by formatting the date correctly on the browser side of using type=β€œdate”