基本上我有这样的模型:
class Playlist(models.Model):
key = models.CharField(max_length=255,blank=True, unique=True)
user = models.ForeignKey(User)
title = models.CharField(max_length=200)
pub_date = models.DateTimeField(auto_now_add=True)
videos = models.ManyToManyField(Video, through='PlaylistVideo')
class PlaylistVideo(models.Model):
playlist = models.ForeignKey(Playlist)
video = models.ForeignKey(Video)
position = models.IntegerField()
class Video(models.Model):
title = models.CharField(max_length=255,blank=True)
description = models.TextField(blank=True)
thumb = models.URLField(blank=True)
duration = models.IntegerField(default=0)
现在我想要一个 API 来返回这样的 PLAYLISTS ......但是视频应该在 PlaylistVideo 模型中按 POSITION 排序
{
"key": "h8x3",
"title": "First Playlist",
"pub_date": "2012-10-11T17:00:26Z",
"videos": [
{
....
},
{
....
}
]
},
我该怎么办?