1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-23 13:34:19 +00:00
pds-2021-g2-nest/nest_backend/database/tables/Tweet.py

26 lines
1.1 KiB
Python
Raw Permalink Normal View History

"""
This module defines the Tweet database class.
"""
2021-05-07 17:46:14 +00:00
from ..base import ext
2021-05-07 17:46:14 +00:00
class Tweet(ext.Model):
__tablename__ = "tweet"
2021-05-07 17:46:14 +00:00
snowflake = ext.Column(ext.String, primary_key=True)
content = ext.Column(ext.String)
2021-05-13 09:40:15 +00:00
location = ext.Column(ext.String)
place = ext.Column(ext.String)
poster = ext.Column(ext.String)
insert_time = ext.Column(ext.DateTime, nullable=False)
2021-05-21 15:40:26 +00:00
post_time = ext.Column(ext.DateTime, nullable=True)
image_url = ext.Column(ext.String, nullable=True)
# Relationships
2021-05-07 17:46:14 +00:00
repositories = ext.relationship("Composed", back_populates="tweet", cascade="all, delete")
conditions = ext.relationship("Contains", back_populates="tweet", cascade="all, delete")
2021-05-13 09:40:15 +00:00
def to_json(self):
return {"snowflake": self.snowflake, "content": self.content, "location": self.location, "poster": self.poster,
2021-05-30 15:47:11 +00:00
"place": self.place, "insert_time": self.insert_time.isoformat(), "post_time": self.post_time.isoformat(),
2021-05-21 15:40:26 +00:00
"image_url": self.image_url, "conditions": [c.condition.to_json() for c in self.conditions]}