Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django Rest框架:在视图集中嵌入视图集_Python_Django_Django Rest Framework - Fatal编程技术网

Python Django Rest框架:在视图集中嵌入视图集

Python Django Rest框架:在视图集中嵌入视图集,python,django,django-rest-framework,Python,Django,Django Rest Framework,我有以下两个Django模型(本例简化) 使用Django Rest框架,我为每个模型设置了ModelSerializer和ModelViewSet。使用@detail\u route和@list\u route装饰器,我设置了以下URL /api/participant/ (GET,POST for list and create) /api/participant/:study_id (GET,PUT for retrieve and update) /api/participant/:st

我有以下两个Django模型(本例简化)

使用Django Rest框架,我为每个模型设置了
ModelSerializer
ModelViewSet
。使用
@detail\u route
@list\u route
装饰器,我设置了以下URL

/api/participant/ (GET,POST for list and create)
/api/participant/:study_id (GET,PUT for retrieve and update)
/api/participant/:study_id/messages (GET for list POST to send message)
我想添加以下url来更改消息元数据。这将使在
restanglar

/api/participant/:study_id/messages/:msg_id (PATCH partial update of message)

如果能够在
参与者
中嵌入
消息
视图集,那就太好了,因为这也会使获取和发布消息的逻辑更简单。这可能吗?如果没有,如何将消息id传递给消息上的@detail\u rouet?

这是嵌套路由器的情况。除了已经提到的那个,我将说出我的名字

就个人而言,我已经将restanglar与drf扩展一起使用。附带缓存支持

关于如何启用嵌套路由的两个提示:

  • 必须在视图集中声明其操作的模型
  • 必须正确遵循嵌套路由器定义
查看DRF嵌套路由器。
/api/participant/:study_id/messages/:msg_id (PATCH partial update of message)