Datetime columns in Flask-SQLAlchemy are datetime
objects. You're using time
module to parse.
Try:
from_date = datetime.datetime.strptime(request.args['from_attendance'],'%m/%d/%Y')
Вопрос
I have the following database structure using SQLAlchemy using Postgresql with Flask:
class Attendance(db.Model):
id = db.Column(db.Integer, primary_key=True)
time = db.Column(db.DateTime(timezone=True))
When I get a date from the user and try and query it against the date of the models:
from_date = time.strptime(request.args['from_attendance'],'%m/%d/%Y')
to_date = time.strptime(request.args['to_attendance'],'%m/%d/%Y')
dates = Attendance.query.filter(Attendance.time < from_date,Attendance.time > to_date).all()
I get the following error:
sqlalchemy.exc.ProgrammingError
ProgrammingError: (ProgrammingError) can't adapt type 'time.struct_time' 'SELECT attendance.id AS attendance_id, attendance.time AS attendance_time, attendance.status AS attendance_status,........
I believe this is a postgresql specific issue, but I am really at a loss for words.
Решение
Datetime columns in Flask-SQLAlchemy are datetime
objects. You're using time
module to parse.
Try:
from_date = datetime.datetime.strptime(request.args['from_attendance'],'%m/%d/%Y')