{% extends 'base.html' %}
{% load crispy_forms_filters %}
{% load i18n %}
{% load custom_filters %}

{% block title %}
        {% trans 'Edit Car' %}
{% endblock %}

{% block content %}
<div class="container p-4">
    <h4 class="mb-4">
            {% trans 'Edit Car' %}
    </h4>

    <!-- Display Validation Errors -->
    {% if form.errors %}
        <div class="alert alert-danger">
            <ul class="mb-0">
                {% for field in form %}
                    {% for error in field.errors %}
                        <li><strong>{{ field.label }}:</strong> {{ error }}</li>
                    {% endfor %}
                {% endfor %}
                {% for error in form.non_field_errors %}
                    <li>{{ error }}</li>
                {% endfor %}
            </ul>
        </div>
    {% endif %}

    <form method="post" class="needs-validation" novalidate>
        {% csrf_token %}
      
                {{ form|crispy }}
         
        <!-- Save and Back Buttons -->
        <div class="d-flex justify-content-center mt-4 ms-2">
            <a href="{{request.META.HTTP_REFERER}}" class="btn btn-sm btn-danger">{% trans "Back" %}</a>
            <button type="submit" class="btn btn-success ms-2">
                {% trans 'Save' %}
            </button>
        </div>
    </form>
</div>

{% endblock %}