mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #18658 -- Improved ModelAdmin.message_user API
Thanks to Lowe Thiderman for the patch and tests
This commit is contained in:
parent
8b659e439b
commit
edf7ad36fa
8 changed files with 133 additions and 7 deletions
|
@ -140,6 +140,15 @@ That's really all there is to it! If you're itching to write your own actions,
|
|||
you now know enough to get started. The rest of this document just covers more
|
||||
advanced techniques.
|
||||
|
||||
Handling errors in actions
|
||||
--------------------------
|
||||
|
||||
If there are foreseeable error conditions that may occur while running your
|
||||
action, you should gracefully inform the user of the problem. This means
|
||||
handling exceptions and and using
|
||||
:meth:`django.contrib.admin.ModelAdmin.message_user` to display a user friendly
|
||||
description of the problem in the response.
|
||||
|
||||
Advanced action techniques
|
||||
==========================
|
||||
|
||||
|
|
|
@ -1303,11 +1303,19 @@ templates used by the :class:`ModelAdmin` views:
|
|||
return qs
|
||||
return qs.filter(author=request.user)
|
||||
|
||||
.. method:: ModelAdmin.message_user(request, message)
|
||||
.. method:: ModelAdmin.message_user(request, message, level=messages.INFO, extra_tags='', fail_silently=False)
|
||||
|
||||
Sends a message to the user. The default implementation creates a message
|
||||
using the :mod:`django.contrib.messages` backend. See the
|
||||
:ref:`custom ModelAdmin example <custom-admin-action>`.
|
||||
Sends a message to the user using the :mod:`django.contrib.messages`
|
||||
backend. See the :ref:`custom ModelAdmin example <custom-admin-action>`.
|
||||
|
||||
.. versionadded:: 1.5
|
||||
|
||||
Keyword arguments allow you to change the message level, add extra CSS
|
||||
tags, or fail silently if the ``contrib.messages`` framework is not
|
||||
installed. These keyword arguments match those for
|
||||
:func:`django.contrib.messages.add_message`, see that function's
|
||||
documentation for more details. One difference is that the level may be
|
||||
passed as a string label in addition to integer/constant.
|
||||
|
||||
.. method:: ModelAdmin.get_paginator(queryset, per_page, orphans=0, allow_empty_first_page=True)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue