2
0

inspectview.rst 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ======================================
  2. Enabling & customising ``InspectView``
  3. ======================================
  4. The ``InspectView`` is disabled by default, as it's not often useful for most
  5. models. However, if you need a view that enables users to view more detailed
  6. information about an instance without the option to edit it, you can easily
  7. enable the inspect view by setting ``inspect_view_enabled=True`` on your
  8. ``ModelAdmin`` class.
  9. When ``InspectView`` is enabled, an 'Inspect' button will automatically appear for each row in
  10. your index / listing view, linking to a new page that shows a list of
  11. field values for that particular object.
  12. By default, all 'concrete' fields (where the field value is stored as a column
  13. in the database table for your model) will be shown. You can customise what
  14. values are displayed by adding the following attributes to your ``ModelAdmin``
  15. class:
  16. .. contents::
  17. :local:
  18. :depth: 1
  19. .. _modeladmin_inspect_view_fields:
  20. ------------------------------------------
  21. ``ModelAdmin.inspect_view_fields``
  22. ------------------------------------------
  23. **Expected value:** A list or tuple, where each item is the name of a field
  24. or attribute on the instance that you'd like ``InspectView`` to render.
  25. A sensible value will be rendered for most field types.
  26. If you have ``wagtail.images`` installed, and the value happens to be an
  27. instance of ``wagtailimages.models.Image`` (or a custom model that subclasses
  28. ``wagtailimages.models.AbstractImage``), a thumbnail of that image will be
  29. rendered.
  30. If you have `wagtail.documents` installed, and the value happens to be an
  31. instance of `wagtaildocs.models.Document` (or a custom model that subclasses
  32. ``wagtaildocs.models.AbstractDocument``), a link to that document will be
  33. rendered, along with the document title, file extension and size.
  34. .. _modeladmin_inspect_view_fields_exclude:
  35. ------------------------------------------
  36. ``ModelAdmin.inspect_view_fields_exclude``
  37. ------------------------------------------
  38. **Expected value:** A list or tuple, where each item is the name of a field
  39. that you'd like to exclude from ``InspectView``
  40. **Note:** If both ``inspect_view_fields`` and ``inspect_view_fields_exclude``
  41. are set, ``inspect_view_fields_exclude`` will be ignored.
  42. .. _modeladmin_inspect_view_extra_css:
  43. -------------------------------------
  44. ``ModelAdmin.inspect_view_extra_css``
  45. -------------------------------------
  46. **Expected value**: A list of path names of additional stylesheets to be added
  47. to the ``InspectView``
  48. See the following part of the docs to find out more:
  49. :ref:`modeladmin_adding_css_and_js`
  50. .. _modeladmin_inspect_view_extra_js:
  51. ------------------------------------
  52. ``ModelAdmin.inspect_view_extra_js``
  53. ------------------------------------
  54. **Expected value**: A list of path names of additional js files to be added
  55. to the ``InspectView``
  56. See the following part of the docs to find out more:
  57. :ref:`modeladmin_adding_css_and_js`
  58. .. _modeladmin_inspect_template_name:
  59. ---------------------------------------
  60. ``ModelAdmin.inspect_template_name``
  61. ---------------------------------------
  62. **Expected value**: The path to a custom template to use for ``InspectView``
  63. See the following part of the docs to find out more:
  64. :ref:`modeladmin_overriding_templates`
  65. .. _modeladmin_inspect_view_class:
  66. ---------------------------------------
  67. ``ModelAdmin.inspect_view_class``
  68. ---------------------------------------
  69. **Expected value**: A custom ``view`` class to replace
  70. ``modeladmin.views.InspectView``
  71. See the following part of the docs to find out more:
  72. :ref:`modeladmin_overriding_views`