Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conflict in type inflection between EmberData and Django REST framework

EmberData is POSTing:

{
  "data": {
    "attributes": {
      "name": "The project name",
      "description": "The project description",
      "price": 123
    },
    "relationships": {
      "onwer": {
        "data": null
      }
    },
    "type": "projects"
  }
}

And Django (drf I guess) is complaining with a 409 Conflict:

{
  "errors": {
    "detail": "The resource object's type (projects) is not the type that constitute the collection represented by the endpoint (project)."
  }
}

Apparently the JSONApi spec does not enforce an inflection rule. How can I tell drf to accept plurals for the type?

like image 312
blueFast Avatar asked Mar 14 '23 17:03

blueFast


2 Answers

There is a config parameter:

JSON_API_PLURALIZE_RELATION_TYPE = True
like image 120
blueFast Avatar answered Apr 16 '23 19:04

blueFast


You could also explicitly set the resource name:

class CategoryViewSet(viewsets.ModelViewSet):
    resource_name = 'categories'
    ...
like image 30
François Constant Avatar answered Apr 16 '23 20:04

François Constant