2021-04-21 16:47:18 +00:00
|
|
|
"""
|
|
|
|
This module defines the Tweet database class.
|
|
|
|
"""
|
|
|
|
|
2021-05-07 17:46:14 +00:00
|
|
|
from ..base import ext
|
2021-04-21 16:47:18 +00:00
|
|
|
|
|
|
|
|
2021-05-07 17:46:14 +00:00
|
|
|
class Tweet(ext.Model):
|
2021-04-21 16:47:18 +00:00
|
|
|
__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-04-21 16:47:18 +00:00
|
|
|
# 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,
|
|
|
|
"place": self.place, "insert_time": self.insert_time.isoformat(),
|
|
|
|
"conditions": [c.condition.to_json() for c in self.conditions]}
|