class User(db.Model, UserMixin):
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(75), nullable=True)
    lname = db.Column(db.String(75), nullable=True)
    username = db.Column(db.String(32), unique=True, nullable=False)
    email = db.Column(db.String(128), unique=True, nullable=False)
    image_file = db.Column(db.String(32), nullable=True, default='default.jpg')
    preflang = db.Column(db.String(20), nullable=True)
    password = db.Column(db.String(60), nullable=False)
    #searches = db.relationship('user_search_history', backref=db.backref('user'))
    #playlists = db.relationship('user_song_playlist', backref=db.backref('user'))
    #songs = db.relationship('Song', secondary=listened)
    posts = db.relationship('Post', backref='author', lazy=True)
    podcasts = db.relationship('Podcast',
                               secondary=subscribed,
                               backref='pod_art',
                               lazy=True)
    listen = db.relationship('Song',
                             secondary=listened,
                             backref=db.backref('listener', lazy=True))
    artist_id = db.Column(db.Integer,
                          db.ForeignKey('artist.id'),
                          nullable=True)
    #playlist_id = db.Column(db.Integer, db.ForeignKey('playlist.id'))
    playlist_id = db.Column(db.Integer,
                            db.ForeignKey('playlist.id'),
                            nullable=True)

    def __repr__(self):
        return f"User('{self.username}', '{self.name}', '{self.email}', '{self.image_file}')"
Exemplo n.º 2
0
class Playlist(db.Model):
    """
    Model for storing playlist information belonging to a specific user
    """
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(50), unique=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    user = db.relationship('User',
                           backref=db.backref('playlists', lazy='dynamic'))

    tracks = db.relationship('Track',
                             secondary=tracks,
                             backref=db.backref('playlists', lazy='dynamic'))

    def __init__(self, title, user):
        self.title = title
        self.user = user

    def __repr__(self):
        return '<Playlist %r>' % (self.title)

    @property
    def serialize(self):
        """Return object data in easily serializeable format"""
        return {
            'id': self.id,
            'title': self.title,
            'user': self.user.serialize,
            'tracks': [item.serialize for item in self.tracks]
        }
class Artist(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(75), nullable=False)
    email = db.Column(db.String(128), unique=True)
    likes = db.Column(db.Integer, default=0)
    dislikes = db.Column(db.Integer, default=0)
    rating = db.Column(db.Integer, default=2)
    song = db.relationship('Song', backref='singer', lazy=True)
    user = db.relationship('User', backref='user_art', uselist=False)
    podcast = db.relationship('Podcast',
                              backref='podcast',
                              lazy=True,
                              uselist=False)
    label_id = db.Column(db.Integer, db.ForeignKey('label.id'))
class Playlist(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=True, default="Your Playlist")
    likes = db.Column(db.Integer, default=0)
    dislikes = db.Column(db.Integer, default=0)
    rating = db.Column(db.Integer, default=2)
    #user = db.relationship('User', backref = 'user', uselist = False)
    contains = db.relationship('Contains',
                               backref='playlist',
                               lazy='dynamic',
                               cascade="all, delete, delete-orphan")
    user = db.relationship('User', backref='user_playlist', uselist=False)

    def __repr__(self):
        return f"Playlist('{self.id}', '{self.rating}')"
Exemplo n.º 5
0
class Artists(db.Model):
    """
    A class to map the artists table using SQLAlchemy

    ...

    Attributes
    -------
    artist_id   : Integer database column
        Holds the id of the artist
    artist      : String databse column
        Holds the artist's name
    albums      : Relationship
        A relationship to albums table
    
    Methods
    -------
    __repr__()
        Method to represent the class object
    """
    artist_id = db.Column(db.Integer, primary_key=True)
    artist = db.Column(db.String(30), nullable=False)
    albums = db.relationship('Albums', backref='albums', lazy=True)

    def __repr__(self):
        return f"Artists('{self.artist}')"
Exemplo n.º 6
0
class Albums(db.Model):
    """
    A class to map the artists table using SQLAlchemy

    ...

    Attributes
    -------
    album_id    : Integer database column
        Holds the id of the album
    album_title : String databse column
        Holds the albums's title
    artist_id   :
        Foreign key for artists table
    songs       : Relationship
        A relationship to songs table
    
    Methods
    -------
    __repr__()
        Method to represent the class object
    """
    album_id = db.Column(db.Integer, primary_key=True)
    album_title = db.Column(db.String(60), nullable=False)
    artist_id = db.Column(db.Integer,
                          db.ForeignKey('artists.artist_id'),
                          nullable=False)
    songs = db.relationship('Songs', backref='songs', lazy=True)

    def __repr__(self):
        return f"Albums('{self.album_title}', {self.artist_id})"
Exemplo n.º 7
0
class AccessToken(db.Model):
    """
    Model for storing OAuth2 token data for a given user
    """
    @classmethod
    def from_json(cls, data):
        token_dict = json.loads(data)
        return cls(token_dict['access_token'], token_dict['token_type'],
                   token_dict['expires_in'], token_dict['refresh_token'])

    id = db.Column(db.Integer, primary_key=True)
    access_token = db.Column(db.String(255))
    token_type = db.Column(db.String(50))
    expires_in = db.Column(db.Integer)
    refresh_token = db.Column(db.String(255))

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User',
                           backref=db.backref('access_token', lazy='dynamic'))

    def __init__(self, access_token, token_type, expires_in, refresh_token):
        self.access_token = access_token
        self.token_type = token_type
        self.expires_in = expires_in
        self.refresh_token = refresh_token
class Event(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=True)
    time = db.Column(db.Integer, nullable=True, default=datetime.utcnow)
    event = db.relationship('EventStatus', backref='events', uselist=False)
    review = db.relationship('Review', backref='review', lazy="dynamic")
    art_perform = db.relationship('Artist',
                                  secondary=performance,
                                  backref='perform',
                                  lazy="dynamic")
    place = db.relationship('Place',
                            secondary=held_in,
                            backref='places',
                            lazy="dynamic")

    def __repr__(self):
        return f"Event('{self.name})"
class Place(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(75), nullable=False)
    address = db.Column(db.String(75), nullable=True)
    pincode = db.Column(db.Integer, nullable=True, unique=True)
    place = db.relationship('City', backref='places', lazy="dynamic")

    def __repr__(self):
        return f"Place('{self.name}', '{self.pincode}')"
class Label(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(75), nullable=False)
    types = db.Column(db.String(75), nullable=True)
    insi = db.Column(db.String(75), nullable=True, unique=True)
    artist = db.relationship('Artist', backref='artist', lazy=True)

    def __repr__(self):
        return f"Label('{self.name}', '{self.insi}')"
class Song(db.Model, UserMixin):
    #__searchable__ = ['name', 'genre']
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(75), nullable=False)
    album = db.Column(db.String(75), nullable=False)
    genre = db.Column(db.String(75), nullable=True)
    release_date = db.Column(db.DateTime,
                             nullable=True,
                             default=datetime.utcnow)
    rating = db.Column(db.Integer, default=2)
    likes = db.Column(db.Integer, default=0)
    dislikes = db.Column(db.Integer, default=0)
    song_file = db.Column(db.String(200), nullable=False)
    image_file = db.Column(db.String(32), nullable=True, default='default.jpg')
    artist_id = db.Column(db.Integer, db.ForeignKey('artist.id'))
    contains = db.relationship('Contains', backref='contains', uselist=False)