如何让django消息保持活动状态(在django管理员中),直到它们被进一步的动作删除?
我使用django消息来提醒用户所需的活动。消息应该显示,直到完成所需的活动。
对于一个视图,我每次调用change_view时都会更新消息。但我不认为这是整个django-admin的解决方案。
admin.py
class InvitationAdmin(admin.ModelAdmin):
def change_view(self, request, object_id, form_url='', extra_context=None):
# keep massages alive
answerSubQuestions = request.session.get('answerSubQuestions')
#add massages
if answerSubQuestions:
for answerid in answerSubQuestions:
answer = Answer.objects.get(pk=answerid)
messages.warning(request, mark_safe('<p style="float:left;line-height:29px;margin-right:15px;">Please add answer for subquestion: </p><a href="%s" class="actionButton actionButtonBlue grp-button" onclick="return showAddAnotherPopup(this);">click here!</a>'%reverse('changeAnswer', args=[answer.id,answer.question.getQuestionType()])))
return super(InvitationAdmin, self).change_view(request, object_id, form_url, extra_context=extra_context)
我希望有类似的东西:
messages.warning(request, mark_safe('Message'), keepalive=True)