I my django-rest-framework I have the following models:
Basically every ride has one final destination and can have multiple middle destinations.
mod
Angular/Django Rest Framework
I had similar problem when trying to post a formdata that has a field with some array values. It turned out that I was using a wrong content-type in the post headers of angular frontend. All I needed was comment out Content-Type.
Post(endpoint, postData) {
let auth = `Bearer ${this.token}`;
let headers = new HttpHeaders({
// "Content-Type": "application/x-www-form-urlencoded",
Authorization: auth
});
let fullurl = `${this.baseUrl}${endpoint}`;
.....
....
}
The issue is that you are passing the name
of the related Destination
object into the serializer, instead of passing the pk
/id
of the Destination
object. So Django REST framework is seeing this and complaining, because it can't resolve LA
into an object.
It sounds like you may actually be looking for a SlugRelatedField, which allows you to identify objects by a slug (LA
in this case) instead of their primary keys.