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 Donation(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) requirementType = db.Column(db.Integer, ForeignKey('RequirementType.id')) quantity = db.Column(db.Integer, nullable=False) status = db.Column(db.String, nullable=False) def __init__(self, requirementType, quantity, status): self.requirementType = requirementType self.quantity = quantity self.status = status
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}'
class Requirements(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) ngo_branch = db.Column(db.Integer, ForeignKey('NGObranch.id')) requirementType = db.Column(db.Integer, ForeignKey('RequirementType.id')) date_created = db.Column(db.DateTime, nullable=False) quantity = db.Column(db.Integer, nullable=False) def __init__(self, ngo_branch, quantity, date_created): self.ngo_branch = ngo_branch self.quantity = quantity self.date_created = date_created
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)
class NGO_Branch(db.Model): __tablename__ = "NGObranch" id = db.Column(db.Integer, primary_key=True, autoincrement=True) ngo_id = db.Column(db.Integer, ForeignKey('ngo.id')) location_X = db.Column(db.Float, nullable=False) location_Y = db.Column(db.Float, nullable=False) Requirements = relationship("Requirements", backref="NGObranch") def __init__(self, ngo_id, location_X, location_Y): self.ngo_id = ngo_id self.location_Y = location_Y self.location_X = location_X
class BlogPost(db.Model): __tablename__ = "posts" id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String, nullable=False) description = db.Column(db.String) author_id = db.Column(db.Integer, ForeignKey('ngo.id')) def __init__(self, title, description): self.title = title self.description = description def __repr__(self): return "title :{}".format(self.title)
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
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 NGO(db.Model): __tablename__ = "ngo" id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String, nullable=False) description = db.Column(db.String, nullable=False) password = db.Column(db.String) branches = relationship("NGO_Branch", backref="Parent-Office") posts = relationship("BlogPost", backref="author") def __init__(self, name, description, password): self.name = name self.description = description self.password = password #bcrypt.generate_password_hash(password) def __repr__(self): return '<name {}'.format(self.name)
class Video(db.Model): id = db.Column(db.Integer, primary_key=True) url = db.Column(db.Text) title = db.Column(db.Text) date = db.Column(db.DateTime) views = db.Column(db.String) desc = db.Column(db.Text) author = db.Column(db.Text) author_img = db.Column(db.Text) cover_img = db.Column(db.Text) def __init__(self, url, date=None): self.url = url if date is None: date = datetime.utcnow() self.date = date
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
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}'
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)
# The examples in this file come from the Flask-SQLAlchemy documentation # For more information take a look at: # http://flask-sqlalchemy.pocoo.org/2.1/quickstart/#simple-relationships from rest_api.database import db book_author_table = db.Table( 'book_author', db.Column('book_id', db.Integer, db.ForeignKey('book.id')), db.Column('author_id', db.Integer, db.ForeignKey('author.id'))) 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] + ". "
class RequirementType(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) type_name = db.Column(db.String, nullable=False)