views.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:umklapp_site 作者: mohrm 项目源码 文件源码
def running_stories(request):
    all_running_stories = Story.objects \
            .filter(is_finished = False) \
            .order_by('title', 'id') \
            .annotate(parts_count = Count('tellers__storyparts',distinct=True)) \
            .annotate(contrib_count = Count('tellers__storyparts__teller', distinct=True)) \
            .annotate(active_count = Count('tellers', distinct=True)) \
            .select_related('started_by') \
            .prefetch_related('always_skip') \
            .prefetch_related('tellers__user') \

    if request.user.is_staff:
        running_stories = all_running_stories
    else:
        running_stories = all_running_stories.filter(tellers__user=request.user)

    user_activity = User.objects \
            .filter(is_staff=False) \
            .annotate(parts_written=Count('teller__storyparts')) \
            .order_by('-parts_written', 'username')[:10]

    context = {
        'username': request.user.username,
        'specialpowers': request.user.is_staff,
        'running_stories': running_stories,
        'finished_stories': finished_stories,
        'user_activity': user_activity,
    }
    return render(request, 'umklapp/running.html', context)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号