コード例 #1
0
ファイル: models.py プロジェクト: Pajko123/FlaskProject
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    sell = db.relationship('Sell', backref='author', lazy=True)

    def get_reset_token(self, expires_sec=1800):
        s = Serializer(app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):
        s = Serializer(app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None
        return User.query.get(user_id)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.image_file}')"
コード例 #2
0
ファイル: models.py プロジェクト: A3AJAGBE/jg-store
class Products(db.Model):
    """Products table"""
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    price = db.Column(db.Integer, nullable=False)
    discount = db.Column(db.Integer)
    stock = db.Column(db.Integer, nullable=False)
    image = db.Column(db.String(128), unique=True, nullable=False)
    category_id = db.Column(db.Integer,
                            db.ForeignKey('categories.id'),
                            nullable=False)
    sub_category_id = db.Column(db.Integer,
                                db.ForeignKey('subcategories.id'),
                                nullable=False)
    cart = db.relationship('Cart', backref='product', lazy=True)

    def __repr__(self):
        return self.name

    @property
    def image_filepath(self):
        """To access the product image filepath"""
        return images.path(self.image)

    def get_percent_saved(self):
        amount_saved = self.price - self.discount
        return round(amount_saved / self.price * 100)

    def get_humanize_price(self):
        return humanize.intcomma(self.price)

    def get_humanize_discount(self):
        return humanize.intcomma(self.discount)
コード例 #3
0
ファイル: models.py プロジェクト: A3AJAGBE/jg-store
class Contact(db.Model):
    """contact table"""
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    email = db.Column(db.String(120), nullable=False)
    message = db.Column(db.Text, nullable=False)
    reply = db.Column(db.String(20))
    reply_status = db.Column(db.String(20), default='Not Sent')

    def __repr__(self):
        return self.name
コード例 #4
0
ファイル: models.py プロジェクト: Pajko123/FlaskProject
class Sell(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    image_file = db.Column(db.String(20), nullable=False, default='def1.jpg')
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    price = db.Column(db.Integer, nullable=False)
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):
        return f"Sell('{self.title}','{self.price}',{self.image_file}, '{self.date_posted}')"
コード例 #5
0
ファイル: user.py プロジェクト: isaacrivas10/fb_chatbot
class User(db.Model, UserMixin):
    id= db.Column(db.Integer, primary_key=True)
    first_name= db.Column(db.String(20), nullable=False)
    last_name= db.Column(db.String(20), nullable=False)
    email= db.Column(db.String(120), unique=True, nullable=False)
    phone_number= db.Column(db.Integer, nullable=False)
    password= db.Column(db.String(60), nullable=False)
    su= db.Column(db.Boolean, default=False)
    is_banned= db.Column(db.Boolean, default=False)
    join_date = db.Column(db.DateTime, index=True,
        default=datetime.utcnow)

    def __repr__(self):
        return f"User('{self.firstName} {self.lastName}', {self.email}, SU:[{self.su}])"
コード例 #6
0
class Category(db.Model):
    id= db.Column(db.Integer, primary_key=True)
    name= db.Column(db.String(20), nullable=False)
    products= db.relationship('Product', backref='category', lazy=True)

    def __repr__(self):
        return f"Category('{self.name}')"
コード例 #7
0
ファイル: models.py プロジェクト: A3AJAGBE/jg-store
class Subcategories(db.Model):
    """Sub Categories table"""
    id = db.Column(db.Integer, primary_key=True)
    sub_category = db.Column(db.String(50), unique=True, nullable=False)
    products = db.relationship('Products', backref='subcategory', lazy=True)

    def __repr__(self):
        return self.sub_category
コード例 #8
0
ファイル: models.py プロジェクト: A3AJAGBE/jg-store
class Roles(db.Model):
    """Roles table"""
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30), unique=True, nullable=False)
    users = db.relationship('Users', backref='role', lazy=True)

    def __repr__(self):
        return self.name
コード例 #9
0
ファイル: models.py プロジェクト: ritsec/hackfortress_store
class User(UserMixin, db.Model):
    """ User class """
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), index=True, unique=True)
    password_hash = db.Column(db.String(128))
    team = db.Column(db.String(4))

    def set_password(self, password):
        """ hashes a password and sets the users hash to the new password """
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):
        """ confirms a password matches the hash """
        return check_password_hash(self.password_hash, password)

    def __repr__(self):
        return '<User {}>'.format(self.username)
コード例 #10
0
ファイル: models.py プロジェクト: A3AJAGBE/jg-store
class Users(UserMixin, db.Model):
    """Users table"""
    id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.String(50), nullable=False)
    last_name = db.Column(db.String(50), nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    email_confirmed = db.Column(db.Boolean(), nullable=False, default=0)
    email_confirmed_at = db.Column(db.DateTime())
    is_active = db.Column(db.Boolean(), nullable=False, default=1)
    password = db.Column(db.String(300), nullable=False)
    role_id = db.Column(db.Integer,
                        db.ForeignKey('roles.id'),
                        nullable=False,
                        default=1)
    cart = db.relationship('Cart', backref='user', lazy=True)
    orders = db.relationship('Orders', backref='user', lazy=True)

    def __repr__(self):
        return f'{self.first_name} {self.last_name}'
コード例 #11
0
class SoldItem(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    time = db.Column(db.DateTime, nullable=False)
    paid_price = db.Column(db.Float, nullable=False)
    sold_quantity = db.Column(db.Integer, nullable=False)
    customer = db.Column(db.String(100))
    sale = db.Column(db.Float, nullable=False, default=0.0)
    debt = db.Column(db.Float, nullable=False)

    item_id = db.Column(db.Integer, db.ForeignKey('main_item.id'))
コード例 #12
0
class Order(db.Model):
    id= db.Column(db.Integer, primary_key=True)
    user_id= db.Column(db.Integer, db.ForeignKey('user.id'))
    order_number= db.Column(db.Integer, nullable=False)
    items= db.relationship('OrderItem', backref='order', lazy=True)
    paid= db.Column(db.Boolean, default=False)
    fulfilled= db.Column(db.Boolean, default=False)
    cancelled= db.Column(db.Boolean, default=False)
    err_msg= db.Column(db.String(60), nullable=True)
    err_log= db.Column(db.PickleType, nullable=True)
    date_placed = db.Column(db.DateTime, index=True,
        default=datetime.utcnow)
コード例 #13
0
class Product(db.Model):
    id= db.Column(db.Integer, primary_key=True)
    product_identifier= db.Column(db.String(10), nullable=False)
    product_name= db.Column(db.String(40), nullable=False)
    product_description= db.Column(db.Text, nullable=False)
    pictures= db.Column(db.PickleType, nullable=False)
    unit_price= db.Column(db.Float, nullable=False)
    product_available= db.Column(db.Boolean, default=True)
    delivery= db.Column(db.String(20), nullable=False)
    brand_id= db.Column(db.Integer, db.ForeignKey('brand.id'))
    category_id= db.Column(db.Integer, db.ForeignKey('category.id'))
    discount_available= db.Column(db.Boolean, default=False)
    discount_percentage= db.Column(db.Float, nullable=True)
    pub_date = db.Column(db.DateTime, index=True,
        default=datetime.utcnow)

    def save_imgs(self, img_list):
        self.pictures= img_list

    def __repr__(self):
        return f"Product('{self.product_identifier}',\
コード例 #14
0
class Employee(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    fname = db.Column(db.String(30), nullable=False)
    lname = db.Column(db.String(30), nullable=False)
    email = db.Column(db.String(100), unique=True, nullable=False)
    phone = db.Column(db.String(30), unique=True, nullable=False)
    role = db.Column(db.String(30), nullable=False)

    salary = db.Column(db.Float)
    incentive = db.Column(db.Float)

    password = db.Column(db.String(60), nullable=False)

    def get_reset_token(self, expires_sec=1800):
        s = Serializer(app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'emp_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):
        s = Serializer(app.config['SECRET_KEY'])
        try:
            emp_id = s.loads(token)['emp_id']
        except:
            return None
        return Employee.query.get(emp_id)

    def __repr__(self):
        return f"{self.fname} {self.lname}"
コード例 #15
0
class Main_item(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    company = db.Column(db.String(100), nullable=False)
    country = db.Column(db.String(100), nullable=False)
    distributer = db.Column(db.String(100), nullable=False)
    family = db.Column(db.String(100), nullable=False)
    # buying_price = db.Column(db.Float, nullable=False)
    selling_price = db.Column(db.Float, nullable=False)
    # total_quantity = db.Column(db.Integer, nullable=False)
    current_quantity = db.Column(db.Integer, nullable=False)

    risk_quantity = db.Column(db.Integer, nullable=False)
    ran_out = db.Column(db.Boolean, default=False)

    place = db.Column(db.String(50), nullable=False)

    bought_items = db.relationship('BoughtItem', backref='item', lazy=True)
    sold_items = db.relationship('SoldItem', backref='item', lazy=True)

    def __repr__(self):
        return f"{self.name}"
コード例 #16
0
class PSNAccounts(db.Model):
    id= db.Column(db.Integer, primary_key=True)
    email= db.Column(db.String(120), nullable=False)
    password= db.Column(db.String(60), nullable=False)
    account_holder= db.Column(db.String(60), nullable=False)
    games= db.Column(db.String(60), nullable=False)
コード例 #17
0
class Expenses(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    paid_price = db.Column(db.Float, nullable=False)
    time = db.Column(db.DateTime, nullable=False)