2
class Article(models.Model):
title = models.CharField(max_length=30)
class Categories(models.Model):
article = models.ForeignKey(Article)
name = models.CharField(max_length=30)
有使用DRF-擴展,它是如何被使用的可能性。
怎麼辦設置有像
/api/article/92285/categories
網址,它應該能夠以服務爲GET,POST響應和PUT
從以下格式
{
"article_id": 92285,
"views": 0,
"downloads": 0,
"shares": 0,
"handle_url": "",
"title": "Test dataset",
"defined_type": "dataset",
"status": "Drafts",
"published_date": "",
"description": "Test description",
"total_size": 0,
"owner": {
"id": 13483,
"full_name": "John Carter"
},
"authors": [
{
"first_name": "John ",
"last_name": "Carter",
"id": 13483,
"full_name": "John Carter"
}
],
"tags": [
],
"categories": [
{
"id": 135,
"name": "Technology"
},
]
"files": [
]
}
--
的base API正在工作,想要設置嵌套的網址,例如/ api/article/92285/categories – bobsr
在這種情況下,您應該重寫您使用的每個類的默認方法實現,就像我對UpdateAPIView所做的一樣。我更新了代碼。 – DhiaTN