Fetching most recent related object for set of objects in Peewee,q = B.select().join(A).group_by(A).having(fn.Max(B.date) == B.date)