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


Python Message.recipient方法代码示例

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


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

示例1: messages

# 需要导入模块: from messages.models import Message [as 别名]
# 或者: from messages.models.Message import recipient [as 别名]
def messages(request, user_id=None):
    context = {}

    message = Message()

    threads = Message.objects.filter(
        recipient=request.user
    ).values_list(
        'sender__user',
        'sender__user__first_name',
        'sender__user__last_name'
    ).distinct()

    if user_id is None and len(threads) > 0:
        first_message = Message.objects.filter(
            Q(recipient=request.user) | Q(sender=request.user)
        )[:1].get()

        current = first_message.recipient if first_message.sender == request.user else first_message.sender
    elif user_id is not None:
        current = user_id
    else:
        current = None

    if request.method == 'POST':
        message.sender = request.user.get_profile()
        message.recipient = UserProfile.objects.get(user__pk=user_id)

        form = MessageForm(request.POST, instance=message)
        form.save()

        return redirect('/messages/' + user_id)
    else:
        form = MessageForm(request.POST, instance=message)


    messages = Message.objects.filter(
        Q(sender=current, recipient=request.user) |
        Q(sender=request.user, recipient=current)
    ).order_by(
        'created'
    )

    context['user'] = request.user
    context['message_form'] = form
    context['current_thread'] = current
    context['threads'] = threads
    context['messages'] = messages

    return render(request, 'messages/index.html', context)
开发者ID:jdavis,项目名称:socialnetwork,代码行数:52,代码来源:views.py

示例2: new_message

# 需要导入模块: from messages.models import Message [as 别名]
# 或者: from messages.models.Message import recipient [as 别名]
def new_message(request, user_id=None):
    context = {}

    message = Message()
    recipient = UserProfile.objects.get(user__pk=user_id)

    if request.method == 'POST':
        message.sender = request.user.get_profile()
        message.recipient = recipient

        form = MessageForm(request.POST, instance=message)
        form.save()

        return redirect('/messages/' + user_id)
    else:
        form = MessageForm(request.POST, instance=message)

    context['user'] = request.user
    context['recipient'] = recipient
    context['form'] = form

    return render(request, 'messages/new.html', context)
开发者ID:jdavis,项目名称:socialnetwork,代码行数:24,代码来源:views.py


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