I want my Django Serializer to validate the format of a date according to several possible formats. Essentially, these formats are:
I know that the final two are possible together, using the DateTimeField
with format= '%Y-%m-%d %H:%M:%S
.
I know the first one is possible by default using the DateField
.
I assume the second one is possible using the DateTimeField
with format= '%Y-%m-%d %H'
, but I haven't tested.
What I want to know is: is there a straightforward way to combine all these validators together, without having to use custom functions/validators? For example, my first instinct was to provide a list of possible formats to the format
parameter on the Date/DateTime
fields, but with no success. Is there something I'm missing?
I got my answer from a comment by Abdul Aziz Barkat:
You want to specify the
input_formats
argument?...