[Fixed]-How do I format Angular Material's md-datepicker for Django REST Framework?

1👍

After more research, I figured it out. Posting the answer in case anyone else encounters this issue.

Basically, md-datepicker stores a JavaScript Date object by default. Trying to send the Date object as-is resulted in the longform string in POST that Django REST Framework couldn’t interpret. Luckily, JS Date objects have a built-in method for generating an ISO-compliant string, which DRF has no problem with. In my controller, I changed the form submission function, using the .toISOString() method to convert the JS object, then making my POST request:

$scope.submitClient = function (data) {
    data.md_date = data.md_date.toISOString();
    $.post({
            url: '/clients/',
            data: data
    })
}
👤jckstl

Leave a comment