使用Django 1.5,Python 2.7
有没有办法可以检查已添加到admin.py
文件中的邮件对象的邮件?在我的管理模型中,我正在覆盖save_model
函数,并且如果它不符合某些条件,则希望停止“模型成功更改”消息。
from django.contrib import admin, messages
class ExampleAdmin(admin.ModelAdmin):
list_display = ('whatever', 'etc')
def save_model(self, request, obj, form, change):
obj.save()
# I want to look at messages right here
答案 0 :(得分:0)
使用get_messages
。
示例:
from django.contrib import admin, messages
class ExampleAdmin(admin.ModelAdmin):
list_display = ('whatever', 'etc')
def save_model(self, request, obj, form, change):
obj.save()
storage = messages.get_messages(request)
for message in storage:
# Examine message here.
pass