Django Rest-Framework nested serializer order

后端 未结 4 1839
我寻月下人不归
我寻月下人不归 2021-02-05 01:40

Is there a way to order a nested serializer _set, for example order by pk or time-stamp.

So basically order song_set

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-05 02:00

    Add ordering meta parameter to your Song model:

    class Song(models.Model):
        album = models.ForeignKey('album.Album', default=1)
        timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
    
        class Meta:
            ordering = ['timestamp', 'pk']
    

提交回复
热议问题