Opened 7 years ago

Closed 7 years ago

#8684 closed (invalid)

Adding custom (succes/failure) messages to the admin site

Reported by: metzeltiger Owned by: nobody
Component: contrib.admin Version:
Severity: Keywords: message, notification
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When you for example save a new object in the admin site this small yellow bar on top will appear telling you "everything's saved correctly".
It would be very useful if you were able to create your own custom messages here.

Change History (1)

comment:1 Changed 7 years ago by kratorius

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

You can do this by overriding ModelAdmin.response_add() (or .response_change), so closing as invalid. Follows an example, just for future reference:

class TestAdmin(admin.ModelAdmin):
    def response_add(self, request, obj, post_url_continue='../%s/'):
        ret = super(Model1Admin, self).response_add(request, obj, post_url_continue)
        request.user.get_and_delete_messages()
        request.user.message_set.create(
                message="Your custom message here"
        )
        return ret
Note: See TracTickets for help on using tickets.
Back to Top