本文整理汇总了Python中forms.MessageForm.receiver_id方法的典型用法代码示例。如果您正苦于以下问题:Python MessageForm.receiver_id方法的具体用法?Python MessageForm.receiver_id怎么用?Python MessageForm.receiver_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.MessageForm
的用法示例。
在下文中一共展示了MessageForm.receiver_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_message
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import receiver_id [as 别名]
def send_message(request, username):
recipient = get_object_or_404(Patient, user__username = username).user
sender = request.user
if request.method == "POST":
form = MessageForm(request.POST)
if form.is_valid():
form.sender_id = sender
form.receiver_id = recipient
message = Message(sender=sender, body=form.cleaned_data['body'], receiver=recipient, read_flag=False)
message.save()
return HttpResponseRedirect(
reverse('conversation', kwargs={"sender_name": message.receiver.username})
)
else:
form = MessageForm()
return TemplateResponse(request, 'send.html', {"form": form, "recipient": recipient})