Beispiel #1
0
def sample_api(flask_app):
    api = Api(flask_app)
    api.add_model(Company)
    api.add_model(Employee)
    api.add_relation(Company.employees, serializer_class=EmployeeSerializer)
    api.add_property(Employee,
                     Employee,
                     "colleagues",
                     serializer_class=EmployeeSerializer)
    api.add_relation(Employee.departments)
    return api
def init_test_data(flask_app, db_session):
    for name, location in CLIENTS:
        company = Company(name=name, location=location)
        db_session.add(company)

    address = Address(street="5th Av.")
    emp1 = Employee(firstname="John", lastname="Doe", address=address)
    db_session.add(address)
    db_session.add(emp1)
    db_session.commit()

    api = Api(flask_app)
    api.add_model(Company)
    api.add_model(Employee, serializer_class=EmployeeSerializer)
    api.add_relation(Company.employees, serializer_class=EmployeeSerializer)
    return api
def sample_api(flask_app):
    api = Api(flask_app)
    api.add_model(Company)
    api.add_model(Employee, serializer_class=EmployeeSerializer)
    api.add_relation(Company.employees, serializer_class=EmployeeSerializer)
    return api
Beispiel #4
0
from flask_restalchemy import Api

from declarative import db
from model.acordo_leniencia import AcordoLeniencia
from model.empresa import Empresa
from serializer.acordo_leniencia import AcordoLenienciaSerializer

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL',
                                                       'sqlite:///:memory:')
db.init_app(app)

api = Api(app)

api.add_model(Empresa)
api.add_model(AcordoLeniencia, serializer_class=AcordoLenienciaSerializer)
api.add_relation(Empresa.acordoLeniencia,
                 serializer_class=AcordoLenienciaSerializer)


@app.route("/")
def hello():
    return u'Olá mundo!'


@app.route("/init_db")
def create_db():
    db.drop_all()
    db.create_all()
    return 'Banco iniciado'