本文整理汇总了Python中models.Status.msg方法的典型用法代码示例。如果您正苦于以下问题:Python Status.msg方法的具体用法?Python Status.msg怎么用?Python Status.msg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Status
的用法示例。
在下文中一共展示了Status.msg方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from models import Status [as 别名]
# 或者: from models.Status import msg [as 别名]
def index(request):
all_messages = Status.objects.all()
if request.method == "POST":
msg_id = request.POST.get("msg_id", None)
del_msg = request.POST.get("del_msg", None)
new_msg = request.POST.get("new_msg", None)
if (msg_id is not None) and (del_msg is not None):
try:
this_status = Status.objects.get(pk=msg_id)
this_status.delete()
success_msg = "Deleted message: {}".format(this_status.msg)
messages.add_message(request, messages.SUCCESS, success_msg)
except:
error_msg = "Something went wrong while deleting message {}".format(msg_id)
messages.add_message(request, messages.ERROR, error_msg)
if new_msg is not None:
try:
new_status = Status()
new_status.msg = new_msg
new_status.save()
success_msg = "Created new message: {}".format(new_msg)
messages.add_message(request, messages.SUCCESS, success_msg)
except:
error_msg = "Something went wrong while creating: {}".format(new_msg)
messages.add_message(request, messages.ERROR, error_msg)
all_msgs = Status.objects.all()
return render_to_response("status_board.html", {"all_msgs": all_msgs}, context_instance=RequestContext(request))