3

I currently have two Models:

class Blog(Model):
  ...

class Entry(Model):
   blog = models.ForeignKey(Blog)
   capture_dt = models.DateTimeField()

If I want blog.entry_set to be ordered by capture_dt, it seems like the best way to get this is adding a Meta class to the Entry model with ordering set to ordering = ('capture_dt', ).

Unfortunately this now changes the global sorting behavior of Entry as opposed to just how I sort when accessing it from the Blog model. Is there a way to set the ordering behavior on a backref per backref basis?

FWIW, SQLAlchemy supports this when declaring the relationship:

class Blog(Base):
    ...
    entry_set = relationship("Entry", order_by="Entry.capture_dt")
Alex Rothberg
  • 10,243
  • 13
  • 60
  • 120

0 Answers0