我目前有两个模型:
class Blog(Model):
...
class Entry(Model):
blog = models.ForeignKey(Blog)
capture_dt = models.DateTimeField()
如果我想blog.entry_set
被订购capture_dt
,似乎最好的方法是Meta
在模型中添加一个类,并将Entry
订购设置为ordering = ('capture_dt', )
。
不幸的是,这现在改变了全局排序行为,Entry
而不是我从Blog
模型访问它时的排序方式。有没有办法在每个 backref 的 backref 基础上设置排序行为?
FWIW,SQLAlchemy 在声明关系时支持这一点:
class Blog(Base):
...
entry_set = relationship("Entry", order_by="Entry.capture_dt")