Hello everyone,
I need send a message to admin from the *save* *method* in a *model*,
something like that:
class MyModel(Displayable, Ownable, RichText):
# some field
def save(self, *args, **kwargs):
# do something
# set the message to be displayed
super(MyModel, self).save(*args, **kwargs)
Then, in the admin, the message should be displayed when the form is sent
(save).
I have done a test after having read documentation, questions on
stackoverflow.com, etc. The test doesn't generate errors during the
execution but I don't get the result I want, the default Mezzanine message
is still displayed, my custom message isn't displayed.
The code of my test would look like that:
from django.db import models
from django.utils.translation import ugettext_lazy as _
from mezzanine.core.models import Displayable, Ownable, RichText
from django.contrib import messages
from django.test import RequestFactory
from django.contrib.messages.storage.fallback import FallbackStorage
def create_request(url):
factory = RequestFactory()
request = factory.get(url)
setattr(request, 'session', 'session')
messages = FallbackStorage(request)
setattr(request, '_messages', messages)
return request
class MyModel(Displayable, Ownable, RichText):
# some field
def save(self, *args, **kwargs):
# do something
url = "/admin/path_to/the_instance/%s/change/" % self.id
request = create_request(url)
messages.error(request, _("My custom message."))
As I said earlier, this does not generate errors, but the message is not
displayed.
Please, how can I do it?
--
You received this message because you are subscribed to the Google Groups
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.