If that's the case you may want to override response_change() instead. This method is quite complex and determines which message to display depending on what action the user just triggered (save, save and continue, save and add new, etc). https://docs.djangoproject.com/en/1.11/_modules/django/contrib/admin/options/#ModelAdmin.response_change

On 2017-10-14 8:30 AM, Rainell Dilou Gómez wrote:
I have changed


|returnDisplayableAdmin.message_user(request,_("My custome message."),messages.WARNING|

by

|
||returnself.message_user(request,_("My custome message."),messages.WARNING)||
|

My custom message (WARNING) is now displayed, but also the predefined Mezzanine message (SUCCESS), both are displayed, as shown in the following image


<https://lh3.googleusercontent.com/-nG8jRIGYOr8/WeIduWfF2mI/AAAAAAAAAew/xmlMNU3SrMwqSS1rtk2aygRVNeRvU2DtQCLcBGAs/s1600/Schermata%2B2017-10-14%2Balle%2B16.22.09.png>


Il giorno venerdì 13 ottobre 2017 22:36:13 UTC+2, Rainell Dilou Gómez ha scritto:

    Hello everyone,
    I need send a message to admin from the /save/ /method/ in a
    /model/, something like that:

    |
    classMyModel(Displayable,Ownable,RichText):

    # some field

    defsave(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 <http://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:

    |
    fromdjango.db importmodels
    fromdjango.utils.translation importugettext_lazy as_
    frommezzanine.core.models importDisplayable,Ownable,RichText

    fromdjango.contrib importmessages
    fromdjango.test importRequestFactory
    fromdjango.contrib.messages.storage.fallback importFallbackStorage

    defcreate_request(url):
        factory =RequestFactory()
        request =factory.get(url)
        setattr(request,'session','session')
        messages =FallbackStorage(request)
        setattr(request,'_messages',messages)
    returnrequest

    classMyModel(Displayable,Ownable,RichText):

    # some field

    defsave(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] <mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.

--
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.

Reply via email to