Reputation:
I am trying to query from two tables.. my appointments and clients. the client number is my foriegn key in appointments that I can pull from the clients database on.
Right now, I am just returning guests to see what it is doing, I am getting this error: TypeError: repr returned non-string (type tuple)
@app.route('/calendar')
def weeklycal():
weekyrnum=request.args.get('weekyr')
guests = db.session.query(Appointments,Clients).filter(Appointments.clientnumber == Clients.clientnumber).filter(Appointments.weekyr == weekyrnum).all()
return
render_template(calbyWeek.html",guests=guests)
How can I query everything from appointments and clients with clientnumber being the column to join on (which is defined as the foreign key in Appointments model), and filter by the week?
Upvotes: 1
Views: 12846
Reputation: 1276
Reference the individual columns from multiple tables in you query, plus make sure you join to additional tables.
guests=db.session.query(Appointments.time,Clients.name).join(Clients).filter(Appointment.clientnumber==Clients.clientnumber).filter(Appointments.weekyr==weekyrnum).all()
If all you actually want is the guests but use Appoitments in you filter then you also just need to add a join.
guests=db.session.query(Clients).join(Appointments).filter(Appointments.clientnumber==Clients.clientnumber).filter(Appointments.weekyr==weekyrnum).all()
Upvotes: 6