File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 2020
2121import logging
2222from datetime import datetime
23+ from typing import Dict
2324
2425from PyMatcha .utils import create_messages_table
2526from PyMatcha .utils .orm import Field
2627from PyMatcha .utils .orm import Model
28+ from timeago import format as timeago_format
2729
2830
2931class Message (Model ):
@@ -61,6 +63,16 @@ def create(
6163 logging .debug ("Created new message" )
6264 return new_message
6365
66+ def to_dict (self ) -> Dict :
67+ returned_dict = super ().to_dict ()
68+ returned_dict ["timestamp_ago" ] = timeago_format (self .timestamp , datetime .utcnow ())
69+ if self .seen_timestamp :
70+ returned_dict ["seen_timestamp_ago" ] = timeago_format (self .seen_timestamp , datetime .utcnow ())
71+ else :
72+ returned_dict ["seen_timestamp_ago" ] = None
73+
74+ return returned_dict
75+
6476 @classmethod
6577 def create_table (cls ):
6678 create_messages_table (cls .db )
You can’t perform that action at this time.
0 commit comments