Exemplo n.º 1
0
class ItemModel(db.Model):
    __tablename__ = 'items'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))
    price = db.Column(db.Float(precision=2))

    def __init__(self, name, price):
        self.name = name
        self.price = price

    def json(self):
        return {'name': self.name, 'price': self.price}

    @classmethod
    def find_by_name(cls, name):
        return cls.query.filter_by(name=name).first()

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    def delete_from_db(self):
        db.session.delete(self)
        db.session.commit()
class Test(db.Model):
    """Test data model"""
    __tablename__ = '{{cookiecutter.table_prefix}}_test'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(128), nullable=False)
    email = db.Column(db.String(128), unique=True, index=True)
    created_timestamp = db.Column(db.DateTime, server_default=func.now())
    updated_timestamp = db.Column(db.DateTime, server_default=func.now(), onupdate=func.now())

    def __init__(self, name, email):
        self.name = name
        self.email = email

    def to_json(self):
        """
        Convert to JSON object
        """
        return {
            'id': self.id,
            'name': self.name,
            'email': self.email,
            'created_timestamp': self.created_timestamp,
            'updated_timestamp': self.updated_timestamp
        }
Exemplo n.º 3
0
class Rented(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    date = db.Column(db.Date)
    disc_id = db.Column(db.Integer, db.ForeignKey('disc.id'))

    def __str__(self):
        return f"<Rented: {self.id}...>"
Exemplo n.º 4
0
class ItemModel(db.Model):
    __tablename__ = 'items'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))
    price = db.Column(db.Float(precision=2))

    store_id = db.Column(db.Integer, db.ForeignKey("stores.id"))
    store = db.relationship('StoreModel')

    def __init__(self, name, price,store_id):
        self.name = name
        self.price = price
        self.store_id = store_id

    def json(self):
        return {'name': self.name, 'price': self.price}

    @classmethod
    def find_by_name(cls, name):

        # SELECT * FROM items WHERE name=name LIMIT 1
        return ItemModel.query.filter_by(name=name).first()

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    def delete_from_db(self):
        db.session.delete(self)
        db.session.commit()
Exemplo n.º 5
0
class Calc(db.Model):
    __tablename__ = 'calcs'
    id = db.Column(db.Integer, primary_key=True)
    w = db.Column(db.Float)
    h = db.Column(db.Float)
    BMI = db.Column(db.Float)
    Desc = db.Column(db.TEXT)
Exemplo n.º 6
0
class School(db.Model):
    __tablename__ = "school"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(120), nullable=False)
    logo = db.Column(db.String(240), nullable=False)
    color = db.Column(db.String(120), nullable=False)
    members = db.relationship('User')
Exemplo n.º 7
0
class StoreModel(db.Model):
    __tablename__ = 'stores'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))

    items = db.relationship('ItemModel', lazy='dynamic')

    def __init__(self, name, price):
        self.name = name
        self.price = price

    def json(self):
        return {'name': self.name, 'items': [item.json() for item in self.items.all()]}

    @classmethod
    def find_by_name(cls, name):
        return cls.query.filter_by(name=name).first()

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    def delete_from_db(self):
        db.session.delete(self)
        db.session.commit()
Exemplo n.º 8
0
class ArtistDisc(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    artist_id = db.Column(db.Integer, db.ForeignKey('artist.id'))
    disc_id = db.Column(db.Integer, db.ForeignKey('disc.id'))

    def __str__(self):
        return f"<ArtistCDs: {self.id} {self.artist_id} {self.cd_id}...>"
Exemplo n.º 9
0
class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), unique=True, index=True)
    role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))

    def __repr__(self):
        return '<User %r>' % self.username
Exemplo n.º 10
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), index=True, unique=True)
    email = db.Column(db.String(120), index=True, unique=True)
    password_hash = db.Column(db.String(128))

    def __repr__(self):
        return '<User {}>'.format(self.username)
Exemplo n.º 11
0
class User(db.Model):
    __tablename__ = "users_user"

    id = db.Column(UUID(), primary_key=True, default=uuid.uuid4)
    email = db.Column(db.String(255), nullable=False, index=True)
    is_active = db.Column(db.Boolean, nullable=False)
    username = db.Column(db.String(64), index=True, nullable=False)
    password = db.Column(db.String(248), nullable=False)
Exemplo n.º 12
0
class OAuth(OAuthConsumerMixin, db.Model):
    """Data model for oauth accounts."""

    __tablename__ = 'oauth'

    provider_user_id = db.Column(db.String(256), unique=True, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey(User.id), nullable=False)
    user = db.relationship("User", back_populates="oauth", uselist=False)
Exemplo n.º 13
0
class Bangumi(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(160), index=True, unique=True, nullable=False)
    time = db.Column(db.DateTime, default=datetime.now)
    url = db.Column(db.String(160))

    def __repr__(self):
        return f'<{type(self).__name__} {self.name}>'
Exemplo n.º 14
0
class Role(db.Model):
    __tablename__ = 'roles'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), unique=True)
    users = db.relationship('User', backref='role', lazy='dynamic')

    def __repr__(self):
        return '<Role %r>' % self.name
Exemplo n.º 15
0
class Log(OurMixin, db.Model):
    __tablename__ = 'logs'

    id = db.Column(db.VARCHAR(length=36), primary_key=True)
    action = db.Column(db.VARCHAR(length=5120))
    user_id = db.Column(db.VARCHAR(length=36),
                        db.ForeignKey('users.id', ondelete='CASCADE'),
                        nullable=False)
    user = db.relationship("User", cascade='delete')
Exemplo n.º 16
0
class Artist(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    artist = db.Column(db.String(100), index=True)
    about = db.Column(db.String(200))
    disc_artist = db.relationship("Disc", backref="artist", lazy="dynamic")
    disc_a_d = db.relationship("ArtistDisc", backref="artist", lazy="dynamic")

    def __str__(self):
        return f"<Artist: {self.name}>"
class Article(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    content = db.Column(db.Text(), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    user = db.relationship(User, backref=db.backref('articles', uselist=True))

    def __repr__(self):
        return '<Article %s>' % self.title
Exemplo n.º 18
0
class Follow(db.Model):
    __tablename__ = "follow"

    id = db.column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    follower_id = db.Column(db.Integer, db.ForeignKey('users.id'))

    user = db.relationship('User', foreign_keys=user_id)
    follower = db.relationship('User', foreign_keys=follower_id)
Exemplo n.º 19
0
class BaseModel(db.Model):
    """
    Abstract model
    """

    __abstract__ = True

    id = db.Column(db.Integer, primary_key=True)
    date_created = db.Column(db.DateTime, default=db.func.current_timestamp())
    date_modified = db.Column(db.DateTime, default=db.func.current_timestamp, onupdate=db.func.current_timestamp)
Exemplo n.º 20
0
class Role(db.Model, RoleMixin):
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(80), unique=True)
    description = db.Column(db.String(255))

    def __str__(self):
        return self.name

    def __hash__(self):
        return hash(self.name)
Exemplo n.º 21
0
class User(UserMixin, db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.Unicode(20), unique=True)
    email = db.Column(db.Unicode(40), unique=True)
    password = db.Column(db.Unicode(30), unique=True)
    listings = db.relationship('Items', backref='user', lazy=True)

    def __repr__(self):
        return '<User: %r>' % self.username + self.email + self.password
Exemplo n.º 22
0
class Transaction(db.Model):
    __tablename__ = "transaction"
    id = db.Column(db.Integer, primary_key=True)
    donor_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    recipient_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    project_id = db.Column(db.Integer, db.ForeignKey('project.id'))
    donation = db.Column(db.Float, nullable=False)

    def __repr__(self):
        return '<User %r>' % self.username
Exemplo n.º 23
0
class ItemModel(db.Model):
    __tablename__ = 'items'
    id = db.Column(db.Integer, primary_key= True)
    name = db.Column(db.String(80))
    price = db.Column(db.Float(precision=2))

    store_id = db.Column(db.Integer, db.ForeignKey('stores.id'))
    store = db.relationship('StoreModel')

    def __init__(self, name, price, store_id):
        self.name = name
        self.price = price
        self.store_id = store_id

    def json(self):
        return {'name': self.name, 'price': self.price}

    @classmethod
    def find_by_name(cls, name):
        # connection = sqlite3.connect('data.db')
        # cursor = connection.cursor()
        # query = "SELECT * FROM items WHERE name=?"
        # result = cursor.execute(query, (name,))
        # row = result.fetchone()
        # connection.close()
        #
        # if row:
        #     return cls(*row)
        return ItemModel.query.filter_by(name=name).first()

    def save_to_db(self):
        # connection = sqlite3.connect('data.db')
        # cursor = connection.cursor()
        # query = 'INSERT INTO items VALUES(?,?)'
        # cursor.execute(query, (self.name, self.price))
        #
        # connection.commit()
        # connection.close()
        db.session.add(self)
        db.session.commit()

    # def update(self):
    #     connection = sqlite3.connect('data.db')
    #     cursor = connection.cursor()
    #
    #     query = 'UPDATE items SET price=? WHERE NAME=?'
    #     cursor.execute(query, (self.name, self.price))
    #
    #     connection.commit()
    #     connection.close()

    def delete_from_db(self):
        db.session.delete(self)
        db.session.commit()
Exemplo n.º 24
0
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}')"
Exemplo n.º 25
0
class User(models.BaseModel):
    """
    Sample user model
    """

    __tablename__ = "auth_user"

    first_name = db.Column(db.String(32), nullable=False)
    last_name = db.Column(db.String(32), nullable=False)
    username = db.Column(db.String(32), nullable=False, unique=True)
    password = db.Column(db.String(32), nullable=False)
Exemplo n.º 26
0
class BaseModel(db.Model):
    """
    Base model used for all models.
    """
    __abstract__ = True
    id = db.Column(db.Integer, primary_key=True)
    {% if cookiecutter.db == "PostgreSQL" %}
    created_at = db.Column(db.DateTime(timezone=True), server_default=func.statement_timestamp())
    updated_at = db.Column(db.DateTime(timezone=True), server_default=func.statement_timestamp(),
                           onupdate=func.clock_timestamp())
    {% endif %}
Exemplo n.º 27
0
class BlogPost(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=True)
    content = db.Column(db.Text, nullable=True)
    author = db.Column(db.String(20), nullable=False, default='N/a')
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)

    def __repr__(self):
        return 'Blog post ' + str(self.id)
Exemplo n.º 28
0
class StoreModel(db.Model):
    __tablename__ = 'stores'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))
    
    items = db.relationship('ItemModel', lazy='dynamic')
    
    
     def __init__(self,name):
        self.name = name
Exemplo n.º 29
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)

    def __init__(self, username, email):
        self.username = username
        self.email = email

    def __repr__(self):
        return '<User %s>' % self.username
Exemplo n.º 30
0
class User(db.Model):
    __tablename__ = 'user'
    id = db.Column('id', db.Integer, primary_key=True)
    email = db.Column(
        'email', db.String(100), unique=True, nullable=False
    )
    passwd = db.Column('passwd', db.String)
    admin = db.Column('admin', db.Boolean)

    def __repr__(self):
        return self.email