예제 #1
0
class Buku(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    isbn = db.Column(db.String(100))
    title = db.Column(db.String(100))
    pengarang = db.Column(db.String(100))
    penerbit = db.Column(db.String(100))
    harga = db.Column(db.Integer)
    status = db.Column(db.String(10))

    client = db.relationship('Client',
                             backref=db.backref('books', lazy='dynamic'))
    client_id = db.Column(db.Integer,
                          db.ForeignKey('client.id'),
                          nullable=False)

    def __init__(self, isbn, title, pengarang, penerbit, harga, status,
                 client):
        self.isbn = isbn
        self.title = title
        self.pengarang = pengarang
        self.penerbit = penerbit
        self.harga = harga
        self.status = status
        self.client = client

    def __repr__(self):
        return '<Buku %r' % self.title
class Author(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))
    surname = db.Column(db.String(50))

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

    def __repr__(self):
        return f'Author: {self.name} {self.surname}'
예제 #3
0
class Client(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(100), unique=True)
    password = db.Column(db.String(100))
    type = db.Column(db.String(20))
    token = db.Column(db.String(300))

    def __init__(self, username, password, type):
        self.username = username
        self.password = password
        self.type = type

    def __repr__(self):
        return '<Client $r' % self.username
예제 #4
0
class Category(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))

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

    def __repr__(self):
        return '<Category %r>' % self.name
class Book(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(80))
    isbn = db.Column(db.String(80), unique=True)
    pub_date = db.Column(db.Integer)
    authors = db.relationship('Author',
                              backref=db.backref('books', lazy='dynamic'),
                              secondary=book_author_table)

    def __init__(self, title, isbn, pub_date=None):
        self.title = title
        self.isbn = isbn
        if pub_date is None:
            pub_date = 0
        self.pub_date = pub_date

    def __repr__(self):
        authors_str = ""
        for author in self.authors:
            authors_str += author.surname + " " + author.name[0] + ". "
        return f'Book: {self.title} {authors_str} {self.isbn} pub_date: {self.pub_date}'
예제 #6
0
class Customer(db.Model) :
    __tablename__ = 't_customer'
    id = db.Column(db.Integer, primary_key=True)
    monae_customer = db.Column(db.Integer, unique=True)
    unix_id = db.Column(db.String(50), unique=True)

    def __init__(self, monae_customer, unix_id) :
        self.monae_customer = monae_customer
        self.unix_id = unix_id

    def __repr__(self) :
        return '<Customer:{}>'.format(self.id)
예제 #7
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(80))
    body = db.Column(db.Text)
    pub_date = db.Column(db.DateTime)

    category_id = db.Column(db.Integer, db.ForeignKey('category.id'))
    category = db.relationship('Category',
                               backref=db.backref('posts', lazy='dynamic'))

    def __init__(self, title, body, category, pub_date=None):
        self.title = title
        self.body = body
        if pub_date is None:
            pub_date = datetime.utcnow()
        self.pub_date = pub_date
        self.category = category

    def __repr__(self):
        return '<Post %r>' % self.title
예제 #8
0
class Contract(db.Model) :
    __tablename__ = 't_contract'
    id = db.Column(db.Integer, primary_key=True)
    monae_quote = db.Column(db.Integer, unique=True)
    monae_invoice = db.Column(db.Integer, unique=True)
    startdate = db.Column(db.Date)
    enddate = db.Column(db.Date)
    flag = db.Column(db.String(10))
    sid = db.Column(db.Integer, db.ForeignKey('t_contract.id'))
    customer_id = db.Column(db.Integer, db.ForeignKey('t_customer.id'))
    customer = db.relationship('Customer', backref=db.backref('contracts', lazy='dynamic'))

    def __init__(self, customer, monae_quote, monae_invoice, startdate, enddate, flag, sid) :
        self.customer = customer
        self.monae_quote = monae_quote
        self.monae_invoice = monae_invoice
        self.startdate = startdate
        self.enddate = enddate
        self.flag = flag
        self.sid = sid

    def __repr__(self) :
        return '<Contract:{}>'.format(self.id)