私はdjango-simple-history(1.8.1)とDRF(3.5.3)を使用しています。私は各要素の歴史を含む休憩サービスを受けたいと思っています。例を見てみましょう!Djangoからの休息履歴を取得する簡単な履歴
models.py
class Product(models.Model):
name = models.CharField(max_length=50)
price = models.IntegerField()
history = HistoricalRecords()
def __str__(self):
return self.name
だから、何がserializers.pyでなければなりませんか?私のような何かを取得したいのですが:
[
{
"id": 1,
"name": "Apple",
"price": 8,
"history": [
{
"history_id": 1,
"id": 1,
"name": "Apple",
"price": 0,
"history_date": "2016-11-22T08:02:08.739134Z",
"history_type": "+",
"history_user": 1
},
{
"history_id": 2,
"id": 1,
"name": "Apple",
"price": 10,
"history_date": "2016-11-22T08:03:50.845634Z",
"history_type": "~",
"history_user": 1
},
{
"history_id": 3,
"id": 1,
"name": "Apple",
"price": 8,
"history_date": "2016-11-22T08:03:58.243843Z",
"history_type": "~",
"history_user": 1
}
]
}
]
解決策を見出すwhitout検索した後、私は最終的に自分でそれを見つけました。しかし、誰かがより良いソリューションを持っている場合...