Skip to content

Commit 5fe45c3

Browse files
committed
Added ago format to messages
1 parent 44ec025 commit 5fe45c3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

backend/PyMatcha/models/message.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020

2121
import logging
2222
from datetime import datetime
23+
from typing import Dict
2324

2425
from PyMatcha.utils import create_messages_table
2526
from PyMatcha.utils.orm import Field
2627
from PyMatcha.utils.orm import Model
28+
from timeago import format as timeago_format
2729

2830

2931
class 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)

0 commit comments

Comments
 (0)