【问题标题】:Conflict in type inflection between EmberData and Django REST frameworkEmberData 和 Django REST 框架之间的类型变形冲突
【发布时间】:2016-04-07 22:54:19
【问题描述】:

EmberDataPOSTing:

{
  "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 规范does not 强制执行变形规则。如何告诉drf 接受该类型的复数形式?

【问题讨论】:

  • 如果你的模型是 project 类型,你不应该从 Ember 提交这个吗?您不是在创建 Projects 模型实例,而是在创建 Project
  • @Ashley'CptLemming'Wilson:如前所述,JSONApi 没有指定这一点 - 这是一个实施决定。两种方式都接受,EmberData方式和Django方式冲突。

标签: django ember-data django-rest-framework json-api


【解决方案1】:

有一个config parameter

JSON_API_PLURALIZE_RELATION_TYPE = True

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2016-04-07
      • 2014-08-25
      • 1970-01-01
      • 1970-01-01
      • 2016-06-20
      • 1970-01-01
      • 1970-01-01
      • 2017-04-25
      • 2012-01-15
      相关资源
      最近更新 更多