create_edit_delete_views.rst 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. ===========================================================
  2. Customising ``CreateView``, ``EditView`` and ``DeleteView``
  3. ===========================================================
  4. **NOTE:** ``modeladmin`` only provides 'create', 'edit' and 'delete'
  5. functionality for non page type models (i.e. models that do not extend
  6. ``wagtailcore.models.Page``). If your model is a 'page type' model, customising
  7. any of the following will not have any effect:
  8. .. _modeladmin_edit_handler_customisation:
  9. -------------------------------------------------------------
  10. Changing which fields appear in ``CreateView`` & ``EditView``
  11. -------------------------------------------------------------
  12. ``edit_handler`` can be used on any Django models.Model class, just like it
  13. can be used for ``Page`` models or other models registered as ``Snippets`` in
  14. Wagtail.
  15. To change the way your ``MyPageModel`` is displayed in the CreateView and the
  16. EditView, simply define an ``edit_handler`` or ``panels`` attribute on your
  17. model class.
  18. .. code-block:: python
  19. class MyPageModel(models.Model):
  20. first_name = models.CharField(max_length=100)
  21. last_name = models.CharField(max_length=100)
  22. address = models.TextField()
  23. panels = [
  24. MultiFieldPanel([
  25. FieldRowPanel([
  26. FieldPanel('first_name', classname='fn'),
  27. FieldPanel('last_name', classname='ln'),
  28. ]),
  29. FieldPanel('address', classname='custom1',))
  30. ]
  31. Or alternatively:
  32. .. code-block:: python
  33. class MyPageModel(models.Model):
  34. first_name = models.CharField(max_length=100)
  35. last_name = models.CharField(max_length=100)
  36. address = models.TextField()
  37. custom_panels = [
  38. MultiFieldPanel([
  39. FieldRowPanel([
  40. FieldPanel('first_name', classname='fn'),
  41. FieldPanel('last_name', classname='ln'),
  42. ]),
  43. FieldPanel('address', classname='custom1',))
  44. ]
  45. edit_handler = ObjectList(custom_panels)
  46. # or
  47. edit_handler = TabbedInterface([ObjectList(custom_panels), ObjectList(...)])
  48. .. _modeladmin_form_view_extra_css:
  49. -----------------------------------
  50. ``ModelAdmin.form_view_extra_css``
  51. -----------------------------------
  52. **Expected value**: A list of path names of additional stylesheets to be added
  53. to ``CreateView`` and ``EditView``
  54. See the following part of the docs to find out more:
  55. :ref:`modeladmin_adding_css_and_js`
  56. .. _modeladmin_form_view_extra_js:
  57. -----------------------------------
  58. ``ModelAdmin.form_view_extra_js``
  59. -----------------------------------
  60. **Expected value**: A list of path names of additional js files to be added
  61. to ``CreateView`` and ``EditView``
  62. See the following part of the docs to find out more:
  63. :ref:`modeladmin_adding_css_and_js`
  64. .. _modeladmin_create_template_name:
  65. -----------------------------------
  66. ``ModelAdmin.create_template_name``
  67. -----------------------------------
  68. **Expected value**: The path to a custom template to use for ``CreateView``
  69. See the following part of the docs to find out more:
  70. :ref:`modeladmin_overriding_templates`
  71. .. _modeladmin_create_view_class:
  72. -----------------------------------
  73. ``ModelAdmin.create_view_class``
  74. -----------------------------------
  75. **Expected value**: A custom ``view`` class to replace
  76. ``modeladmin.views.CreateView``
  77. See the following part of the docs to find out more:
  78. :ref:`modeladmin_overriding_views`
  79. .. _modeladmin_edit_template_name:
  80. -----------------------------------
  81. ``ModelAdmin.edit_template_name``
  82. -----------------------------------
  83. **Expected value**: The path to a custom template to use for ``EditView``
  84. See the following part of the docs to find out more:
  85. :ref:`modeladmin_overriding_templates`
  86. .. _modeladmin_edit_view_class:
  87. -----------------------------------
  88. ``ModelAdmin.edit_view_class``
  89. -----------------------------------
  90. **Expected value**: A custom ``view`` class to replace
  91. ``modeladmin.views.EditView``
  92. See the following part of the docs to find out more:
  93. :ref:`modeladmin_overriding_views`
  94. .. _modeladmin_delete_template_name:
  95. -----------------------------------
  96. ``ModelAdmin.delete_template_name``
  97. -----------------------------------
  98. **Expected value**: The path to a custom template to use for ``DeleteView``
  99. See the following part of the docs to find out more:
  100. :ref:`modeladmin_overriding_templates`
  101. .. _modeladmin_delete_view_class:
  102. -----------------------------------
  103. ``ModelAdmin.delete_view_class``
  104. -----------------------------------
  105. **Expected value**: A custom ``view`` class to replace
  106. ``modeladmin.views.DeleteView``
  107. See the following part of the docs to find out more:
  108. :ref:`modeladmin_overriding_views`