本文整理汇总了Python中event.models.Event.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Event.get_by_id方法的具体用法?Python Event.get_by_id怎么用?Python Event.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类event.models.Event
的用法示例。
在下文中一共展示了Event.get_by_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from event.models import Event [as 别名]
# 或者: from event.models.Event import get_by_id [as 别名]
def get(self, key):
event = None
if key and key != 'add':
event = Event.get_by_id(int(key))
if event:
ctx = {
'event': event,
}
building_str = get_building_str(event.building)
ctx.update({building_str: True})
template = JINJA_ENVIRONMENT.get_template('single_event.html')
self.response.write(template.render(ctx))
else:
ctx = {}
template = JINJA_ENVIRONMENT.get_template('404.html')
self.response.write(template.render(ctx))
示例2: post
# 需要导入模块: from event.models import Event [as 别名]
# 或者: from event.models.Event import get_by_id [as 别名]
def post(self):
eventid = self.request.POST.get('eventid')
name = self.request.POST.get('name')
time = self.request.POST.get('datetime')
building = self.request.POST.get('building')
kwargs = {
'name': name,
'time': datetime.strptime(time, "%d/%m/%Y %H:%M:%S"),
'building': get_building_obj(building),
}
event = None
if eventid:
event = Event.get_by_id(int(eventid))
if not event:
event = Event(**kwargs)
event.put()
self.redirect("/events")
else:
event.name = name
event.time = datetime.strptime(time, "%d/%m/%Y %H:%M:%S")
event.building = get_building_obj(building)
event.put()
self.redirect('/events')