object_edit.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. {% extends 'base/layout.html' %}
  2. {% load form_helpers %}
  3. {% load helpers %}
  4. {% block title %}
  5. {% if obj.pk %}Editing {{ obj_type }} {{ obj }}{% else %}Add a new {{ obj_type }}{% endif %}
  6. {% endblock title %}
  7. {% block tabs %}
  8. <ul class="nav nav-tabs px-3">
  9. <li class="nav-item" role="presentation">
  10. <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">
  11. {% if obj.pk %}Edit{% else %}Create{% endif %}
  12. </button>
  13. </li>
  14. </ul>
  15. {% endblock tabs %}
  16. {% block content-wrapper %}
  17. <div class="tab-content">
  18. <div class="tab-pane show active" id="edit-form" role="tabpanel" aria-labelledby="object-list-tab">
  19. {# Link to model documentation #}
  20. {% if obj and settings.DOCS_ROOT %}
  21. <div class="float-end">
  22. <a href="{{ obj|get_docs_url }}" target="_blank" class="btn btn-sm btn-outline-secondary" title="View model documentation">
  23. <i class="mdi mdi-help-circle"></i> Help
  24. </a>
  25. </div>
  26. {% endif %}
  27. <form action="" method="post" enctype="multipart/form-data" class="form-object-edit">
  28. {% csrf_token %}
  29. {% for field in form.hidden_fields %}
  30. {{ field }}
  31. {% endfor %}
  32. {% block form %}
  33. {% if form.Meta.fieldsets %}
  34. {# Render grouped fields according to Form #}
  35. {% for group, fields in form.Meta.fieldsets %}
  36. <div class="field-group my-5">
  37. <div class="row mb-2">
  38. <h5 class="offset-sm-3">{{ group }}</h5>
  39. </div>
  40. {% for name in fields %}
  41. {% render_field form|getfield:name %}
  42. {% endfor %}
  43. </div>
  44. {% endfor %}
  45. {% if form.custom_fields %}
  46. <div class="field-group my-5">
  47. <div class="row mb-2">
  48. <h5 class="offset-sm-3">Custom Fields</h5>
  49. </div>
  50. {% render_custom_fields form %}
  51. </div>
  52. {% endif %}
  53. {% if form.comments %}
  54. <div class="field-group my-5">
  55. <h5 class="text-center">Comments</h5>
  56. {% render_field form.comments %}
  57. </div>
  58. {% endif %}
  59. {% else %}
  60. {# Render all fields in a single group #}
  61. <div class="field-group my-5">
  62. {% block form_fields %}{% render_form form %}{% endblock %}
  63. </div>
  64. {% endif %}
  65. {% endblock form %}
  66. <div class="text-end my-3">
  67. {% block buttons %}
  68. <a class="btn btn-outline-danger" href="{{ return_url }}">Cancel</a>
  69. {% if obj.pk %}
  70. <button type="submit" name="_update" class="btn btn-primary">
  71. Save
  72. </button>
  73. {% else %}
  74. <button type="submit" name="_addanother" class="btn btn-outline-primary">
  75. Create & Add Another
  76. </button>
  77. <button type="submit" name="_create" class="btn btn-primary">
  78. Create
  79. </button>
  80. {% endif %}
  81. {% endblock buttons %}
  82. </div>
  83. </form>
  84. </div>
  85. </div>
  86. {% endblock content-wrapper %}