我第一次使用 django-rest-framework api。这是我的问题:
我需要设计一个数据库,其中有两个表:
- Server => 保存服务器信息,如ip地址和服务器名称
id: INT, name: VARCHAR, ip_address: VARCHAR
- 部署 => 服务器上的部署,包括部署日期和评论消息
id: INT, server_id: FK to Server, deploy_date: DATETIME, message: VARCHAR
我被要求跟踪部署信息并设计以下 API:
get /servers/ => get all the server information with the latest deploy on that server
Example:
[
{
"id" : 1,
"name" : "qa-001",
"ip_address" : "192.168.1.1",
"deploy" :
{
"id" : 1,
"deploy_date" : "2013-09-09 12:00:00",
"message" : "test new api"
}
},
{
"id" : 2,
"name" : "qa-002",
"ip_address" : "192.168.1.2",
"deploy" :
{
"id" : 2,
"deploy_date" : "2013-09-10 12:00:00",
"message" : "test second message"
}
}
]
get /deploys/ => get all the deploy information
Example:
[
{
"id" : 1,
"deploy_date" : "2013-09-09 12:00:00",
"message" : "test new api",
"server_id" : 1
},
{
"id" : 2,
"deploy_date" : "2013-09-10 12:00:00",
"message" : "test second message",
"server_id" : 2
},
{
"id" : 3,
"deploy_date" : "2013-09-08 12:00:00",
"message" : "test new api",
"server_id" : 1
}
]
// Deploy 3 does not show up in the get servers return json
// because deploy 1 was deployed on the same server but later than deploy 3.
POST /deploys/ => To insert a new deploy
POST /servers/ => To insert a new server
...
我玩过 django-rest-framework 教程代码并阅读了不同的 api 文档,但不知道如何实现我上面列出的功能。
如果您对如何实现此功能有任何想法,或者您认为另一种数据库设计更适合此要求,请告诉我。
谢谢!