本文整理汇总了Python中photos.models.Photo.create方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.create方法的具体用法?Python Photo.create怎么用?Python Photo.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类photos.models.Photo
的用法示例。
在下文中一共展示了Photo.create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_init
# 需要导入模块: from photos.models import Photo [as 别名]
# 或者: from photos.models.Photo import create [as 别名]
def test_init(args):
users = [('viewer 1', '[email protected]', 'pass1', False),
('viewer 2', '[email protected]', 'pass2', False),
('uploader 1', '[email protected]', 'uppass1', True),
('uploader 2', '[email protected]', 'uppass2', True)]
photos = [('111', '2014-06-07T20:21:19', 'photo 111'),
('12345', '2014-06-05T20:21:19', 'photo 12345'),
('222', '2014-06-04T20:21:19', 'photo 222'),
('333', '2014-06-07T22:21:19', 'photo 333'),
('444', '2014-06-05T20:21:19', '444'),
('555', '2014-06-01T20:21:19', 'photo 555'),
('666', '2014-06-05T14:21:19', 'photo 666'),
('abcde', '2014-05-02T20:21:19', 'photo abcde'),
('uvw', '2014-03-02T20:21:19', 'photo uvw'),
('xyz', '2014-07-02T20:21:19', 'photo xyz'),
]
if User.select().count() == 0:
for n, e, p, u in users:
User.create(name=n, email=e, password=generate_password_hash(p), uploader=u)
else:
print('User table already contains data')
str2datetime = lambda s: arrow.get(s).datetime.replace(tzinfo=None)
if Photo.select().count() == 0:
for s, d, c in photos:
kw = dict(chksum=s, date=str2datetime(d), comment=c,
added=datetime.utcnow(),
mimetype='image/jpeg')
print(kw)
Photo.create(**kw)
else:
print('Photo table already contains data')