class Track(db.Model): __tablename__ = "tracks" id = db.Column(db.Integer, primary_key=True) album_id = db.Column(db.Integer, db.ForeignKey("albums.id"), nullable=False) album = db.relationship("Album", back_populates="tracks") artist_id = db.Column(db.Integer, db.ForeignKey("artists.id"), nullable=False) artist = db.relationship("Artist", back_populates="tracks") disc_number = db.Column(db.Integer, nullable=False, default=1) duration_ms = db.Column(db.Integer, nullable=False) explicit = db.Column(db.Boolean, nullable=False, default=False) href = db.Column(db.String(), nullable=False, default="https://api.spotify.com/tracks/<id>") name = db.Column(db.String(), nullable=False) popularity = db.Column(db.Integer, nullable=False, default=0) preview_url = db.Column(db.String(), nullable=False, default="https://p.scdn.co/mp3-preview/<id>") track_number = db.Column(db.Integer, nullable=False) object_type = db.Column(db.String(20), nullable=False, default="track") uri = db.Column(db.String(), nullable=False, default="spotify:track:<id>") is_local = db.Column(db.Boolean, nullable=False, default=False)
class Album(db.Model): __tablename__ = "albums" id = db.Column(db.Integer, primary_key=True) album_type = db.Column(db.String(20), nullable=False, default="album") artist_id = db.Column(db.Integer, db.ForeignKey("artists.id"), nullable=False) artist = db.relationship("Artist", back_populates="albums") copyright = db.Column(db.String(100), nullable=False) copyright_type = db.Column(db.String(1), nullable=False) genre = db.Column(db.String(20), nullable=False) href = db.Column(db.String(), nullable=False, default="https://api.spotify.com/albums/<id>") label = db.Column(db.String(50), nullable=False) name = db.Column(db.String(), nullable=False) release_date = db.Column(db.Integer, nullable=False) release_date_precision = db.Column(db.String(5), nullable=False, default="year") object_type = db.Column(db.String(20), nullable=False, default="album") tracks = db.relationship("Track", back_populates="album") uri = db.Column(db.String(), nullable=False, default="spotify:album:<id>") def __repr__(self): return f"<Album {self.name}>"
class Checklist(db.Model): __tablename__ = "checklists" id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(), nullable=False) owner_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False) is_group = db.Column(db.Boolean, nullable=False, default=False) repeat_id = db.Column(db.Integer, nullable=False, default=0) description = db.Column(db.String()) thumbnail_image = db.Column(db.String()) users = db.relationship("User", secondary=users_checklists, back_populates="checklists") items = db.relationship("Item", backref="checklist", cascade="all, delete-orphan")
class Artist(db.Model): __tablename__ = "artists" id = db.Column(db.Integer, primary_key=True) albums = db.relationship("Album", back_populates="artist") followers = db.Column(db.Integer, nullable=False, default=0) genre = db.Column(db.String(20), nullable=False) href = db.Column(db.String(), nullable=False, default="https://api.spotify.com/artists/<id>") name = db.Column(db.String(), nullable=False) popularity = db.Column(db.Integer, nullable=False, default=0) object_type = db.Column(db.String(20), nullable=False, default="artist") tracks = db.relationship("Track", back_populates="artist") uri = db.Column(db.String(), nullable=False, default="spotify:artist:<id>") def __repr__(self): return f"<Artist {self.name}>"
class Teams_Pokemon(db.Model): __tablename__ = "teams_pokemon" id = db.Column(db.Integer, db.Sequence("teams_pokemon_id_seq"), unique=True, autoincrement=True) team_id = db.Column(db.Integer, db.ForeignKey("teams.id"), primary_key=True) team_index = db.Column(db.Integer, primary_key=True) pokeapi_id = db.Column(db.Integer, db.ForeignKey("pokemon.pokeapi_id")) pokemon = db.relationship("Pokemon") pokemon_moves = db.relationship("Pokemon_Moves", cascade="all, delete-orphan") def __repr__(self): return f"<Team {self.team_id}, Slot {self.team_index}>"
class Pokemon_Moves(db.Model): __tablename__ = "pokemon_moves" team_pokemon_id = db.Column(db.Integer, db.ForeignKey("teams_pokemon.id"), primary_key=True) pokeapi_id = db.Column(db.Integer, db.ForeignKey("pokemon.pokeapi_id"), primary_key=True) pokemon_move_index = db.Column(db.Integer, primary_key=True) move_id = db.Column(db.Integer, db.ForeignKey("moves.move_id")) move = db.relationship("Move") def __repr__(self): return f"<Pokemon #{self.pokeapi_id}, Slot {self.pokemon_move_index}>"
class Show(db.Model): __tablename__ = "shows" movie_id = db.Column(db.Integer, db.ForeignKey('movies.id'), primary_key=True) cinema_id = db.Column(db.Integer, db.ForeignKey('cinemas.id'), primary_key=True) show_times = db.Column(db.String(8), nullable=False, primary_key=True) show_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) no_of_seats = db.Column('no_of_seats', db.Integer, nullable=False) cinema = db.relationship("Cinema", backref="shows")
class Movie(db.Model): """ Model form movie details """ __tablename__ = "movies" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(120), nullable=False) release_date = db.Column(db.DateTime) cinemas = db.relationship("Cinema", secondary='shows', back_populates="movies")
class Cinema(db.Model): """ Model for cinemas """ __tablename__ = "cinemas" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(120), nullable=False) show_times = db.Column(ARRAY(db.String(8))) city = db.Column(db.Integer, db.ForeignKey('cities.id'), nullable=False) movies = db.relationship("Movie", secondary='shows', back_populates="cinemas")
class City(db.Model): """ List of cities which are playing movies """ __tablename__ = "cities" id = db.Column(db.Integer, primary_key=True) city_name = db.Column(db.String(80), nullable=False) cinemas = db.relationship("Cinema") @hybrid_property def movies(self): return list(chain(*[cinema.movies for cinema in self.cinemas]))
class User(db.Model): __tablename__ = "users" id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(), nullable=False, unique=True) password = db.Column(db.String(), nullable=False) username = db.Column(db.String(), nullable=False, unique=True) name = db.Column(db.String()) profile_image = db.Column(db.String()) timezone = db.Column(db.Integer, nullable=False, default=0) has_reminders = db.Column(db.Boolean, nullable=False, default=False) reminder_time = db.Column(db.Integer, default=None) checklists = db.relationship("Checklist", secondary=users_checklists, back_populates="users") owned_checklists = db.relationship("Checklist", backref="owner", cascade="all, delete-orphan") items = db.relationship("Item", backref="assigned_to") def __repr__(self): return f"<User {self.email}>"
class Track_Rating(db.Model): __tablename__ = "track_ratings" user_id = db.Column(db.Integer, db.ForeignKey("users.id"), primary_key=True) track_id = db.Column(db.Integer, db.ForeignKey("tracks.id"), primary_key=True) rating = db.Column(db.Integer, nullable=False) track = db.relationship("Track") def __repr__(self): return f"<Track_Rating User: {self.user_id}, Track: {self.track_id}>"
class User(db.Model): __tablename__ = "users" id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(), nullable=False, unique=True) password = db.Column(db.String(), nullable=False) country = db.Column(db.String(2), nullable=True) display_name = db.Column(db.String(30), nullable=True) href = db.Column(db.String(), nullable=False, default="https://api.spotify.com/users/<id>") product = db.Column(db.String(20), nullable=False, default="free") object_type = db.Column(db.String(20), nullable=False, default="user") uri = db.Column(db.String(), nullable=False, default="spotify:user:<id>") track_ratings = db.relationship("Track_Rating", backref="user") admin = db.Column(db.Boolean, nullable=False, default=False) def __repr__(self): return f"<User {self.email}>"
class User(db.Model): """ User model for storing user data """ __tablename__ = "users" id = db.Column(db.Integer, primary_key=True) phone_number = db.Column(db.String(10), unique=True, nullable=False) password = db.Column(db.String(128), nullable=False) tickets = db.relationship("Ticket") @classmethod def check_password(cls, password, _hash): return django_pbkdf2_sha256.verify(password, _hash) def pre_commit_setup(self): """ This method generates the required fields either from available information else automatic fields are generated. """ self.password = django_pbkdf2_sha256.hash(self.password)
class User(db.Model, UserMixin): __tablename__ = "users" id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(), nullable=False, unique=True) username = db.Column(db.String(30), nullable=False, unique=True) password = db.Column(db.String(), nullable=False) teams = db.relationship("Team", backref="owner", cascade="all, delete-orphan") def __repr__(self): return f"<User {self.email}>" @classmethod def check_unique_email(cls, email): """ Checks uniqueness of an email address, returns True if unique """ if User.query.filter_by(email=email).first(): return False return True @classmethod def check_unique_username(cls, username): """ Checks uniqueness of a username, returns True if unique """ if User.query.filter_by(username=username).first(): return False return True def check_password(self, password): """ Checks that password data entered in a form matches the password has in the database """ return bcrypt.check_password_hash(self.password, password)
class FeatureRequest(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(80), nullable = False) description = db.Column(db.String(120)) client_id = db.Column(db.Integer, db.ForeignKey('client.id'), nullable = False) client = db.relationship("Client", back_populates = "feature_requests") def __init__(self, title, description, client_id): self.title = title self.description = description self.client_id = client_id def __repr__(self): return '<FeatureRequest %s>' % self.title def jsonify(self): """Return JSON representation of the object""" return { 'id' : self.id, 'title': self.title, 'description': self.description, 'client_id': self.client_id }
class Team(db.Model): __tablename__ = "teams" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), nullable=False) description = db.Column(db.String(2000), nullable=True) is_private = db.Column(db.Boolean, nullable=False, default=True) owner_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False) team_pokemon = db.relationship("Teams_Pokemon", backref="team", cascade="all, delete-orphan") def __repr__(self): return f"<Team {self.id}: {self.name}>" @staticmethod def sort_team_pokemon(teams): """ Sorts pokemon in team.team_pokemon by team index for a list of teams """ if type(teams) == list: for team in teams: team.team_pokemon.sort(key=lambda x: x.team_index) return teams @staticmethod def fill_empty_team_slots(team_list_dict): """ Takes a list of team dicts and fills empty pokemon slots with None """ for team in team_list_dict: indices = [pokemon["team_index"] for pokemon in team["team_pokemon"]] for i in range(6): if i + 1 not in indices: team["team_pokemon"].insert(i, None) return team_list_dict
class Client(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80), nullable=False) feature_requests = db.relationship("FeatureRequest", back_populates="client") def __init__(self, name): self.name = name def __repr__(self): return '<Client %s>' % self.name def jsonify(self): """Return JSON representation of the object""" return { 'id': self.id, 'name': self.name, 'feature_requests': [ feature_request.jsonify() for feature_request in self.feature_requests ] }