object_edit.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. {% extends 'base/layout.html' %}
  2. {% load form_helpers %}
  3. {% load helpers %}
  4. {% comment %}
  5. Blocks:
  6. form: Content within the <form> element
  7. buttons: Form submission buttons
  8. Context:
  9. object: Python instance of the object being edited
  10. form: The edit form
  11. return_url: The URL to which the user is redirected after submitting the form
  12. {% endcomment %}
  13. {% block title %}
  14. {% if object.pk %}Editing {{ object|meta:"verbose_name" }} {{ object }}{% else %}Add a new {{ object|meta:"verbose_name" }}{% endif %}
  15. {% endblock title %}
  16. {% block tabs %}
  17. <ul class="nav nav-tabs px-3">
  18. <li class="nav-item" role="presentation">
  19. <button class="nav-link active" id="edit-form-tab" data-bs-toggle="tab" data-bs-target="#edit-form" type="button" role="tab" aria-controls="edit-form" aria-selected="true">
  20. {% if object.pk %}Edit{% else %}Create{% endif %}
  21. </button>
  22. </li>
  23. </ul>
  24. {% endblock tabs %}
  25. {% block content-wrapper %}
  26. <div class="tab-content">
  27. <div class="tab-pane show active" id="edit-form" role="tabpanel" aria-labelledby="object-list-tab">
  28. {# Warn about missing prerequisite objects #}
  29. {% if prerequisite_model %}
  30. {% include 'inc/missing_prerequisites.html' %}
  31. {% endif %}
  32. {# Link to model documentation #}
  33. {% if object and settings.DOCS_ROOT %}
  34. <div class="float-end">
  35. <a href="{{ object|get_docs_url }}" target="_blank" class="btn btn-sm btn-outline-secondary" title="View model documentation">
  36. <i class="mdi mdi-help-circle"></i> Help
  37. </a>
  38. </div>
  39. {% endif %}
  40. <form action="" method="post" enctype="multipart/form-data" class="form-object-edit mt-5">
  41. {% csrf_token %}
  42. {% block form %}
  43. {% if form.fieldsets %}
  44. {# Render hidden fields #}
  45. {% for field in form.hidden_fields %}
  46. {{ field }}
  47. {% endfor %}
  48. {# Render grouped fields according to Form #}
  49. {% for group, fields in form.fieldsets %}
  50. <div class="field-group mb-5">
  51. <div class="row mb-2">
  52. <h5 class="offset-sm-3">{{ group }}</h5>
  53. </div>
  54. {% for name in fields %}
  55. {% with field=form|getfield:name %}
  56. {% if not field.field.widget.is_hidden %}
  57. {% render_field field %}
  58. {% endif %}
  59. {% endwith %}
  60. {% endfor %}
  61. </div>
  62. {% endfor %}
  63. {% if form.custom_fields %}
  64. <div class="field-group mb-5">
  65. <div class="row mb-2">
  66. <h5 class="offset-sm-3">Custom Fields</h5>
  67. </div>
  68. {% render_custom_fields form %}
  69. </div>
  70. {% endif %}
  71. {% if form.comments %}
  72. <div class="field-group mb-5">
  73. <h5 class="text-center">Comments</h5>
  74. {% render_field form.comments %}
  75. </div>
  76. {% endif %}
  77. {% else %}
  78. {# Render all fields in a single group #}
  79. <div class="field-group mb-5">
  80. {% render_form form %}
  81. </div>
  82. {% endif %}
  83. {% endblock form %}
  84. <div class="text-end my-3">
  85. {% block buttons %}
  86. {% if object.pk %}
  87. <button type="submit" name="_update" class="btn btn-primary">
  88. Save
  89. </button>
  90. {% else %}
  91. <button type="submit" name="_create" class="btn btn-primary">
  92. Create
  93. </button>
  94. <button type="submit" name="_addanother" class="btn btn-outline-primary">
  95. Create & Add Another
  96. </button>
  97. {% endif %}
  98. <a class="btn btn-outline-danger" href="{{ return_url }}">Cancel</a>
  99. {% endblock buttons %}
  100. </div>
  101. </form>
  102. </div>
  103. </div>
  104. {% endblock content-wrapper %}