object_edit.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 mt-5">
  28. {% csrf_token %}
  29. {% block form %}
  30. {% if form.Meta.fieldsets %}
  31. {# Render hidden fields #}
  32. {% for field in form.hidden_fields %}
  33. {{ field }}
  34. {% endfor %}
  35. {# Render grouped fields according to Form #}
  36. {% for group, fields in form.Meta.fieldsets %}
  37. <div class="field-group mb-5">
  38. <div class="row mb-2">
  39. <h5 class="offset-sm-3">{{ group }}</h5>
  40. </div>
  41. {% for name in fields %}
  42. {% with field=form|getfield:name %}
  43. {% if not field.field.widget.is_hidden %}
  44. {% render_field field %}
  45. {% endif %}
  46. {% endwith %}
  47. {% endfor %}
  48. </div>
  49. {% endfor %}
  50. {% if form.custom_fields %}
  51. <div class="field-group mb-5">
  52. <div class="row mb-2">
  53. <h5 class="offset-sm-3">Custom Fields</h5>
  54. </div>
  55. {% render_custom_fields form %}
  56. </div>
  57. {% endif %}
  58. {% if form.comments %}
  59. <div class="field-group mb-5">
  60. <h5 class="text-center">Comments</h5>
  61. {% render_field form.comments %}
  62. </div>
  63. {% endif %}
  64. {% else %}
  65. {# Render all fields in a single group #}
  66. <div class="field-group mb-5">
  67. {% block form_fields %}{% render_form form %}{% endblock %}
  68. </div>
  69. {% endif %}
  70. {% endblock form %}
  71. <div class="text-end my-3">
  72. {% block buttons %}
  73. <a class="btn btn-outline-danger" href="{{ return_url }}">Cancel</a>
  74. {% if obj.pk %}
  75. <button type="submit" name="_update" class="btn btn-primary">
  76. Save
  77. </button>
  78. {% else %}
  79. <button type="submit" name="_addanother" class="btn btn-outline-primary">
  80. Create & Add Another
  81. </button>
  82. <button type="submit" name="_create" class="btn btn-primary">
  83. Create
  84. </button>
  85. {% endif %}
  86. {% endblock buttons %}
  87. </div>
  88. </form>
  89. </div>
  90. </div>
  91. {% endblock content-wrapper %}