class Record(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) # 记录条目id uid = db.Column(db.Integer, db.ForeignKey('user.id')) # 记录属于的用户id date = db.Column(db.Date) # 日期 habit_id = db.Column(db.Integer, db.ForeignKey('habit.id', ondelete = 'CASCADE')) # 习惯id habit_name = db.Column(db.String(20)) # 习惯名称 remark = db.Column(db.Text) # 备注 is_complete = db.Column(db.String(1)) # 是否完成
class Podcast(db.Model): ################################################# # podcasts ################################################# __tablename__ = 'Podcasts' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('Users.id')) username = db.Column(db.String(64)) # basic info author = db.Column(db.String(64), index=True) podname = db.Column(db.String(128), index=True) podlink = db.Column(db.String(256), unique=True) image_path = db.Column(db.String(512)) poddesc = db.Column(db.String(1024)) buildtime = db.Column(db.DateTime, index=True, default=datetime.utcnow) rsslink = db.Column(db.String(256), unique=True) # itunes info it_own_name = db.Column(db.String(64)) it_own_email = db.Column(db.String(256)) it_cat = db.Column(db.String(128)) it_subcat = db.Column(db.String(128)) it_sum = db.Column(db.String(1024)) it_subtitle = db.Column(db.String(256)) it_keys = db.Column(db.String(512)) it_explicit = db.Column(db.String(32)) pod_eps = db.relationship('Episode', backref='Podcasts', lazy='dynamic') def __repr__(self): return '<Podcast {}>'.format(self.body)
class Team(db.Model): """ name: name of team description: description of team image: image url publisher: main publisher for team characters: characters in team volumes: volumes that team appeard in """ __tablename__ = "Team" name = db.Column(db.String(50), unique=True, primary_key=True) description = db.Column(db.String, unique=False) image = db.Column(db.String) # image url appear = db.Column(db.String, unique=False) num_appearances = db.Column(db.String, unique=False) publisher_name = db.Column(db.String(150), db.ForeignKey('Publisher.name')) team_publisher = db.relationship("Publisher", back_populates="publisher_teams") team_characters = db.relationship("Character", secondary=characters_teams, back_populates='character_teams') team_volumes = db.relationship("Volume", secondary=volumes_teams, back_populates='volume_teams') def __repr__(self): return 'Team(name={}, description={}, image={}, publisher={}, appear={}, num_appearances={}'.format( self.name, self.description, self.image, self.team_publisher, self.appear, self.num_appearances, ) + ")" def json_it(self): c = [] for char in self.team_characters: c += {'name': char.name, 'image': char.image} v = [] for volume in self.team_volumes: v += {'name': volume.name, 'image': volume.image} ans = { 'appear': self.appear, 'description': self.description, 'image': self.image, 'name': self.name, 'num_appearances': self.num_appearances, 'publisher_name': self.publisher_name, 'image': self.image, 'num_appearances': self.num_appearances, 'team_characters': c, 'team_volumes': v } return ans
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) content = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"Post('{self.title}', '{self.date_posted}')"
class Wish(db.Model): __tablename__ = 'wish' id = db.Column(db.Integer, primary_key=True, autoincrement=True) description = db.Column(db.String(100)) create_date_time = db.Column(db.DateTime, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) def __repr__(self): return 'Wish-{0} created at {1}: {2}.'.format(self.id, self.create_date_time, self.description)
class Volume(db.Model): """ image: image url description: info on volume count_of_issues: num issues in volume start_year: when volume started publisher: main publisher characters: characters in volume teams: teams in the characters name: name of volume """ __tablename__ = "Volume" image = db.Column(db.String) # image url description = db.Column(db.String(200), unique=False) start_year = db.Column(db.Integer, unique=False) name = db.Column(db.String, unique=True, primary_key=True) num_issues = db.Column(db.String) publisher_name = db.Column(db.String(150), db.ForeignKey('Publisher.name')) volume_publisher = db.relationship("Publisher", back_populates="publisher_volumes") volume_characters = db.relationship("Character", secondary='characters_volumes', back_populates="character_volumes") volume_teams = db.relationship("Team", secondary=volumes_teams, back_populates='team_volumes') def json_it(self): t = [] for team in self.character_teams: t += {'name': team.name, 'image': team.image} c = [] for character in self.character_volumes: c += {'name': character.name, 'image': character.image} ans = { 'description': self.description, 'image': self.image, 'name': self.name, 'num_issues': self.num_issues, 'publisher_name': self.publisher_name, 'start_year': self.start_year, 'volume_teams': t, 'volume_characters': c } return ans def __repr__(self): return 'Volume(image={}, description={}, start_year={}, publisher={}, name={}, num_issues={}'.format( self.image, self.description, self.start_year, self.publisher_name, self.name, self.num_issues) + ")"
class Episode(db.Model): ################################################# # All podcast episodes ################################################# __tablename__ = 'Episodes_' + str(db.ForeignKey('Podcasts.id')) id = db.Column(db.Integer, primary_key=True) #user_id = db.Column(db.Integer, db.ForeignKey('users.id')) pod_id = db.Column(db.Integer, db.ForeignKey('Podcasts.id')) epname = db.Column(db.String(128), index=True) epnum = db.Column(db.String(64), index=True) epdesc = db.Column(db.String(1024)) audio_path = db.Column(db.String(256)) eplink = db.Column(db.String(256), unique=True) # episode website link # itunes info it_sum = db.Column(db.String(1024)) it_subtitle = db.Column(db.String(256)) def __repr__(self): return '<Episode {}>'.format(self.body)
class Habit(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) # 习惯id uid = db.Column(db.Integer, db.ForeignKey('user.id')) # 习惯属于的用户 habit_name = db.Column(db.String(20)) # 习惯名称 records = db.relationship('Record', backref='habit', lazy=True, cascade='all, delete-orphan', passive_deletes = True) # 包含的习惯记录
class Character(db.Model): """ name: name of characters birth: when the character was born image: image url gender: male or female creator: creator name volumes: volumes that character is in teams: teams that character is in publisher: publisher character is with appear: first appearance real: real name if it exists num_apperances: num of appearnces """ __tablename__ = "Character" name = db.Column(db.String(150), unique=True, primary_key=True) birth = db.Column(db.String(100), unique=False) image = db.Column(db.String) # image url gender = db.Column(db.String(10)) creator = db.Column(db.String(50), unique=False) appear = db.Column(db.String, unique=False) real = db.Column(db.String, unique=False) num_appearances = db.Column(db.String, unique=False) publisher_name = db.Column(db.String(150), db.ForeignKey('Publisher.name')) character_publisher = db.relationship( "Publisher", back_populates="publisher_characters") character_volumes = db.relationship("Volume", secondary=characters_volumes, back_populates="volume_characters") character_teams = db.relationship("Team", secondary=characters_teams, back_populates="team_characters") def __repr__(self): return 'Character(name={}, image={}, birth={}, gender={}, creator={}, publisher={}, appear={}, real={}, num_appearances={}'.format( self.name, self.image, self.birth, self.gender, self.creator, self.publisher_name, self.appear, self.real, self.num_appearances) + ")" def json_it(self): t = [] for team in self.character_teams: t += {'name': team.name, 'image': team.image} v = [] for volume in self.character_volumes: v += {'name': volume.name, 'image': volume.image} ans = { 'name': self.name, 'appear': self.appear, 'birth': self.birth, 'character_publisher': self.character_publisher, 'creator': self.creator, 'gender': self.gender, 'image': self.image, 'num_appearances': self.num_appearances, 'real': self.real, 'character_teams': t, 'character_volumes': v } return ans
# from afsiodfajf.database import Base # afsafsf is going to be our database name from demo import db characters_volumes = db.Table( 'characters_volumes', db.Column('character_name', db.String(150), db.ForeignKey('Character.name')), db.Column('volume_name', db.String(100), db.ForeignKey('Volume.name'))) characters_teams = db.Table( 'characters_teams', db.Column('character_name', db.String(200), db.ForeignKey('Character.name')), db.Column('team_name', db.String(250), db.ForeignKey('Team.name'))) volumes_teams = db.Table( 'volumes_teams', db.Column('volume_name', db.String(200), db.ForeignKey('Volume.name')), db.Column('team_name', db.String(150), db.ForeignKey('Team.name'))) class Character(db.Model): """ name: name of characters birth: when the character was born image: image url gender: male or female creator: creator name volumes: volumes that character is in teams: teams that character is in publisher: publisher character is with
class Team(db.Model): """ name: name of team description: description of team image: image url publisher: main publisher for team characters: characters in team volumes: volumes that team appeard in """ __tablename__ = "Team" name = db.Column(db.String(50), unique=True, primary_key=True) description = db.Column(db.String, unique=False) image = db.Column(db.String) # image url appear = db.Column(db.String, unique=False) num_appearances = db.Column(db.String, unique=False) publisher_name = db.Column(db.String(150), db.ForeignKey('Publisher.name')) team_publisher = db.relationship("Publisher", back_populates="publisher_teams") team_characters = db.relationship("Character", secondary=characters_teams, back_populates='character_teams') team_volumes = db.relationship("Volume", secondary=volumes_teams, back_populates='volume_teams') # TsVector column used for searching. tsvector_col = db.Column(TsVector) # Create an index for the tsvector column __table_args__ = (db.Index('team_tsvector_idx', 'tsvector_col', postgresql_using='gin'), ) def __repr__(self): return 'Team(name={}, description={}, image={}, publisher={}, appear={}, num_appearances={}'.format( self.name, self.description, self.image, self.team_publisher, self.appear, self.num_appearances, ) + ")" def json_it(self): c = [] for char in self.team_characters: temp = {'name': char.name, 'image': char.image} c.append(temp) v = [] for volume in self.team_volumes: temp = {'name': volume.name, 'image': volume.image} v.append(temp) ans = { 'appear': self.appear, 'description': self.description, 'image': self.image, 'name': self.name, 'num_appearances': self.num_appearances, 'publisher_name': self.publisher_name, 'image': self.image, 'num_appearances': self.num_appearances, 'team_characters': c, 'team_volumes': v } return ans
class Volume(db.Model): """ image: image url description: info on volume count_of_issues: num issues in volume start_year: when volume started publisher: main publisher characters: characters in volume teams: teams in the characters name: name of volume """ __tablename__ = "Volume" image = db.Column(db.String) # image url description = db.Column(db.String(200), unique=False) start_year = db.Column(db.String(100), unique=False) name = db.Column(db.String, unique=True, primary_key=True) num_issues = db.Column(db.String) publisher_name = db.Column(db.String(150), db.ForeignKey('Publisher.name')) volume_publisher = db.relationship("Publisher", back_populates="publisher_volumes") volume_characters = db.relationship("Character", secondary='characters_volumes', back_populates="character_volumes") volume_teams = db.relationship("Team", secondary=volumes_teams, back_populates='team_volumes') # TsVector column used for searching. tsvector_col = db.Column(TsVector) # Create an index for the tsvector column __table_args__ = (db.Index('volume_tsvector_idx', 'tsvector_col', postgresql_using='gin'), ) def json_it(self): t = [] for team in self.volume_teams: temp = {'name': team.name, 'image': team.image} t.append(temp) c = [] for character in self.volume_characters: temp = {'name': character.name, 'image': character.image} c.append(temp) ans = { 'description': self.description, 'image': self.image, 'name': self.name, 'num_issues': self.num_issues, 'publisher_name': self.publisher_name, 'start_year': self.start_year, 'volume_teams': t, 'volume_characters': c } return ans def __repr__(self): return 'Volume(image={}, description={}, start_year={}, publisher={}, name={}, num_issues={}'.format( self.image, self.description, self.start_year, self.publisher_name, self.name, self.num_issues) + ")"