Python models.Role() Examples

The following are 5 code examples of models.Role(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module models , or try the search function .
Example #1
Source File: database.py    From graphql-pynamodb with MIT License 5 votes vote down vote up
def init_db():
    # import all modules here that might define models so that
    # they will be registered properly on the metadata.  Otherwise
    # you will have to import them first before calling init_db()
    from models import Department, Employee, Role
    for model in [Department, Employee, Role]:
        if model.exists():
            model.delete_table()
        model.create_table(read_capacity_units=1, write_capacity_units=1, wait=True)

    # Create the fixtures
    engineering = Department(id=str(uuid4()), name='Engineering')
    engineering.save()
    hr = Department(id=str(uuid4()), name='Human Resources')
    hr.save()

    manager = Role(id=str(uuid4()), name='manager')
    manager.save()

    engineer = Role(id=str(uuid4()), name='engineer')
    engineer.save()

    peter = Employee(id=str(uuid4()), name='Peter', department=engineering, role=engineer)
    peter.save()

    roy = Employee(id=str(uuid4()), name='Roy', department=engineering, role=engineer)
    roy.save()

    tracy = Employee(id=str(uuid4()), name='Tracy', department=hr, role=manager)
    tracy.save() 
Example #2
Source File: database.py    From graphene-sqlalchemy with MIT License 5 votes vote down vote up
def init_db():
    # import all modules here that might define models so that
    # they will be registered properly on the metadata.  Otherwise
    # you will have to import them first before calling init_db()
    from models import Department, Employee, Role
    Base.metadata.drop_all(bind=engine)
    Base.metadata.create_all(bind=engine)

    # Create the fixtures
    engineering = Department(name='Engineering')
    db_session.add(engineering)
    hr = Department(name='Human Resources')
    db_session.add(hr)

    manager = Role(name='manager')
    db_session.add(manager)
    engineer = Role(name='engineer')
    db_session.add(engineer)

    peter = Employee(name='Peter', department=engineering, role=engineer)
    db_session.add(peter)
    roy = Employee(name='Roy', department=engineering, role=engineer)
    db_session.add(roy)
    tracy = Employee(name='Tracy', department=hr, role=manager)
    db_session.add(tracy)
    db_session.commit() 
Example #3
Source File: database.py    From graphene-sqlalchemy with MIT License 5 votes vote down vote up
def init_db():
    # import all modules here that might define models so that
    # they will be registered properly on the metadata.  Otherwise
    # you will have to import them first before calling init_db()
    from models import Department, Employee, Role
    Base.metadata.drop_all(bind=engine)
    Base.metadata.create_all(bind=engine)

    # Create the fixtures
    engineering = Department(name='Engineering')
    db_session.add(engineering)
    hr = Department(name='Human Resources')
    db_session.add(hr)

    manager = Role(name='manager')
    db_session.add(manager)
    engineer = Role(name='engineer')
    db_session.add(engineer)

    peter = Employee(name='Peter', department=engineering, role=engineer)
    db_session.add(peter)
    roy = Employee(name='Roy', department=engineering, role=engineer)
    db_session.add(roy)
    tracy = Employee(name='Tracy', department=hr, role=manager)
    db_session.add(tracy)
    db_session.commit() 
Example #4
Source File: database.py    From graphene-mongo with MIT License 5 votes vote down vote up
def init_db():
    # Create the fixtures
    engineering = Department(name="Engineering")
    engineering.save()

    hr = Department(name="Human Resources")
    hr.save()

    manager = Role(name="manager")
    manager.save()

    engineer = Role(name="engineer")
    engineer.save()

    debug = Task(name="Debug")
    test = Task(name="Test")

    tracy = Employee(name="Tracy", department=hr, roles=[engineer, manager], tasks=[])
    tracy.save()

    peter = Employee(
        name="Peter",
        department=engineering,
        leader=tracy,
        roles=[engineer],
        tasks=[debug, test],
    )
    peter.save()

    roy = Employee(
        name="Roy",
        department=engineering,
        leader=tracy,
        roles=[engineer],
        tasks=[debug],
    )
    roy.save() 
Example #5
Source File: admin.py    From flask-restless-security with MIT License 5 votes vote down vote up
def init_admin():
    admin = Admin(app)
    admin.add_view(UserModelView(User, db.session, category='Auth'))
    admin.add_view(AdminModelView(Role, db.session, category='Auth'))
    admin.add_view(AdminModelView(SomeStuff, db.session))
    admin.add_view(LogoutView(name='Logout', endpoint='logout'))
    admin.add_view(LoginView(name='Login', endpoint='login'))