J
J
Jekson2020-03-09 17:25:22
Django
Jekson, 2020-03-09 17:25:22

Datefield field validation in DRF?

I can not understand why it does not accept an empty value for the field DateField

models.py

class Vendors(models.Model):
    ...
    nda = models.DateField(blank=True, null=True)


I send this json
{
    "vendor_name": "The Greey sAlsbudm2",
    "country": "Belarus",
    "nda": "2020-12-23",
    "contacts": [{"contact_name": "Mrk", "phone": "2373823", "email": "[email protected]"},
            {
            "contact_name": "Uio",
            "phone": "34567",
            "email": "[email protected]"
        }
    ]

    
}

Everything is fine, but if I leave the nda field empty

{
    "vendor_name": "The Greey sAlsbudm2",
    "country": "Belarus",
    "nda": "",
     ...
    
}


I get
{
    "nda": [
        "Date has wrong format. Use one of these formats instead: YYYY-MM-DD."
    ]
}


The model says that blank=True.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2020-03-09
@Lepilov

pass null instead of an empty string.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question