Answer the question
In order to leave comments, you need to log in
How to send a message to django admin?
Django admin shows messages like "category "Photo" has been successfully added."
How can I send my messages directly from the model, that is, the user saves the Foto category, it already exists, how can I send a message to the admin panel?
Something like this:
def save(self, *args, **kwargs):
if Category.objects.filter(self.slug):
return u'Такая категория уже есть'
Answer the question
In order to leave comments, you need to log in
from django.contrib import messages
class MyAdmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
if blablabla:
messages.add_message('Category already exists.', level=messages.INFO)
else:
return super(MyAdmin, self).save_model(request, obj, form, change)
unique=True
the category name field.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question