Django model default sort order using related table field

后端 未结 6 1281
半阙折子戏
半阙折子戏 2020-12-17 08:26

Is it possible to set the default sort order for a model to a field from a related model (rather than the integer key) i.e. something that yields a SQL order by clause with

6条回答
  •  生来不讨喜
    2020-12-17 09:02

    I use django 1.2.7 and instead of connecting ForeignKey.Attribute we should use "__", so this code will work:

    class Meta:
        ordering = ('bar_date', 'related__name', )
    

提交回复
热议问题