本文整理汇总了Python中messages.models.Message.sender方法的典型用法代码示例。如果您正苦于以下问题:Python Message.sender方法的具体用法?Python Message.sender怎么用?Python Message.sender使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类messages.models.Message
的用法示例。
在下文中一共展示了Message.sender方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: messages
# 需要导入模块: from messages.models import Message [as 别名]
# 或者: from messages.models.Message import sender [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)
示例2: new_message
# 需要导入模块: from messages.models import Message [as 别名]
# 或者: from messages.models.Message import sender [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)