EmberData和Django REST框架之间的类型变化冲突



EmberDataPOST ing:

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

Django(我猜是drf)正在抱怨409 Conflict:

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

显然,JSONApi规范没有强制执行拐点规则。如何告诉drf接受该类型的复数?

有一个配置参数:

JSON_API_PLURALIZE_RELATION_TYPE = True

您还可以显式设置资源名称:

class CategoryViewSet(viewsets.ModelViewSet):
    resource_name = 'categories'
    ...

最新更新