本文整理匯總了Python中models.Employee方法的典型用法代碼示例。如果您正苦於以下問題:Python models.Employee方法的具體用法?Python models.Employee怎麽用?Python models.Employee使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models
的用法示例。
在下文中一共展示了models.Employee方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: init_db
# 需要導入模塊: import models [as 別名]
# 或者: from models import Employee [as 別名]
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()
示例2: init_db
# 需要導入模塊: import models [as 別名]
# 或者: from models import Employee [as 別名]
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()
示例3: init_db
# 需要導入模塊: import models [as 別名]
# 或者: from models import Employee [as 別名]
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()