本文整理汇总了Python中model.User.User.address方法的典型用法代码示例。如果您正苦于以下问题:Python User.address方法的具体用法?Python User.address怎么用?Python User.address使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User.User
的用法示例。
在下文中一共展示了User.address方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_db
# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import address [as 别名]
def test_db():
# INSERT
if not session.query(exists().where(User.email == '[email protected]')).scalar():
u1 = User()
u1.name = "Test user"
u1.email = "[email protected]"
a1 = Address()
a1.street = "Str 123"
a1.city = "City WTF"
u1.address = a1
session.add(a1)
session.add(u1)
session.commit()
# check if record exists in db:
# print session.query(Address).filter_by(city='City WTF').count()
# print bool( session.query(Address).filter_by(city='City WTF').count() )
# SELECT
if session.query(exists().where(Address.city == 'City WTF')).scalar():
a2 = session.query(Address).filter_by(city='City WTF').first()
print a2.city
if bool(session.query(Address).filter_by(city='City WTF').count()):
a2 = session.query(Address).filter_by(city='City WTF').first()
print a2.city
# UPDATE
if session.query(exists().where(User.email == '[email protected]')).scalar():
session.query(User).filter_by(email='[email protected]').update({"nick": "a"})
session.commit()
if session.query(exists().where(User.email == '[email protected]')).scalar():
u = session.query(User).filter_by(email='[email protected]').first()
u.nick = "b"
session.commit()
# DELETE
if session.query(exists().where(User.email == '[email protected]')).scalar():
session.query(User).filter_by(email='[email protected]').delete()
session.commit()
if session.query(exists().where(Address.city == 'City WTF')).scalar():
session.query(Address).filter_by(city='City WTF').delete()
session.commit()