当前位置: 首页>>代码示例>>Python>>正文


Python Event.beer方法代码示例

本文整理汇总了Python中models.Event.beer方法的典型用法代码示例。如果您正苦于以下问题:Python Event.beer方法的具体用法?Python Event.beer怎么用?Python Event.beer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Event的用法示例。


在下文中一共展示了Event.beer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: beer_gone

# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import beer [as 别名]
def beer_gone(request, beer_id):
    beer = get_object_or_404(Beer, pk=beer_id)

    if beer.current_state() == 6:
        messages.error(request, "This beer is already marked as 'gone'!")
        return redirect('beer-show', beer.id)

    # Create a new event marking this beer as gone
    event = Event()
    event.beer = beer
    event.date = datetime.datetime.now().date()
    event.event_type = 6    # Hard-coding this is kind of gross...
    event.completed = True
    event.save()

    tweet_event.delay(event)

    return redirect('beer-show', beer.id)
开发者ID:nickpegg,项目名称:home,代码行数:20,代码来源:views.py

示例2: beer_new

# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import beer [as 别名]
def beer_new(request):
    if not request.user.is_superuser:
        return redirect('brewhouse-display')

    if request.method == 'POST':
        form = AddBeerForm(request.POST)
        if form.is_valid():
            b = Beer()
            b.name = form.cleaned_data['name']
            b.style = form.cleaned_data['style']
            b.recipe_url = form.cleaned_data['recipe_url']
            b.save()

            # Create some basic events based on the brewed-on date
            # tuple is of (event_type, days_since_brew_date)
            brew_date = form.cleaned_data['brew_date']

            events = (
                (7, 0),     # brewing
                (1, 0),     # brewed
                (2, 0),     # primary fermentation
                (3, 7),     # secondary fermentation
                (4, 21),    # kegged
                (0, 28),    # ready!
            )

            for etype, num_days in events:
                event = Event()
                event.beer = b
                event.event_type = etype
                event.date = brew_date + datetime.timedelta(days=num_days)
                event.save()

            return redirect('beer-show', b.id)
        else:
            pass    # TODO set an error
    else:
        form = AddBeerForm()

    return render(request, 'brewhouse/new_beer.html', locals())
开发者ID:nickpegg,项目名称:home,代码行数:42,代码来源:views.py


注:本文中的models.Event.beer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。