I am working with a Flask application where I have a LargeGroupAttendance model that references another model called Attendee. I'm trying to query all the LargeGroupAttendance objects that match certain criteria, but I'm trying to sort them by the Attendee model column - is that possible? The following are two models:
""" Attendeee Class """
class Attendee(Base):
__tablename__ = 'attendee'
id = Column(Integer, primary_key=True)
first_name = Column(String(200))
last_name = Column(String(200))
year = Column(String(200))
email = Column(String(100), unique=True)
dorm = Column(String(100))
def __init__(self, first_name, last_name, year, email, dorm):
self.first_name = first_name
self.last_name = last_name
self.year = year
self.email = email
self.dorm = dorm
def __repr__(self):
return '<Attendee %r>' % self.first_name
""" Large Group Attendance Class """
class LargeGroupAttendance(Base):
__tablename__ = 'large_group_attendance'
id = Column(Integer, primary_key=True)
first_time = Column(Integer)
large_group_id = Column(Integer, ForeignKey('large_group.id'))
large_group = relationship("LargeGroup", backref=backref('large_group_attendance', order_by=id))
attendee_id = Column(Integer, ForeignKey('attendee.id'))
attendee = relationship("Attendee", backref=backref('large_group_attendance', order_by=id))
Do I need to add something to my member class to make this possible? And here is the request that I tried before, but it had no way out (no errors either ...). Where am I mistaken?
attendance_records = db.session.query(LargeGroupAttendance).filter_by(large_group_id=event_id).order_by(desc(LargeGroupAttendance.attendee.first_name))
source
share