[Django]-How to make post request of an object with array property in django rest framework

3👍

Well, the error is explicit enough I think.

What DRF expects is:

{
    "empID": "DJS1003",
    "fullname": "Doe, John Smith",
    "contactnumber": [
        {
            "contactnumber": "123456789"
        },
        {
            "contactnumber": "321456879"
        }
   ]
}

What you’re sending:

{
    "empID": "101",
    "fullname": "John Doe",
    "contactnumber": [
        "444-1234",
        "0911-124-7854"
   ]
}

So, you need your JS to send an Array of dicts.
You could also tweak some relation field to make this happen but it’s a bit more complex because you’ll need both the employee ID and phone number to check unicity.

Leave a comment