これは私のコードで、他の場所でNotification.create_timesqlalchemyクエリでdatetimeを文字列に変更する方法は?
result = session.query(
Notification.content, cls.is_read,
Notification.create_time).join(
cls, Notification.id == cls.notification).filter(
and_(cls.user == user_id)).order_by(
Notification.create_time.desc()).all()
を照会、フロントエンドにjson.dumpsクエリ結果に必要な日時フォーマットは望めないjson.dumpsので、私はこのようにやりたい:
session.query(Notification.create_time.strftime('%Y-%m-%d %H:%M'))
だから、datetimeをsqlalchemyクエリの文字列に変更するにはどうすればよいですか?
これはDB固有のものです。 Postgresqlは、タイムスタンプの書式設定のために['to_char'](https://www.postgresql.org/docs/current/static/functions-formatting.html)を使用しています。これは[' sqlalchemy.func'](http ://docs.sqlalchemy.org/en/latest/core/functions.html)。しかし、より良い解決策は、[datetime'オブジェクトを扱うJSONシリアライザを使うことです](http://stackoverflow.com/questions/23285558/datetime-date2014-4-25-is-not-json-serializableイン・ジャンゴ)。 –
あなたは素晴らしいです、ありがとう、非常にありがとうございます。私のアイデアは間違ったway.XDに行く – alvy