I have a problem. I'm a beginner in django and python and I need help. I have a page with list of cars and all cars have a button with info. Now, this button redirects me to another page but I want to open this detail view not in a new page but in modal on the same page. I tried many solutions but none of them didn't work in my case.
This is my page with a list of cars car_list.html . It's about car_detailURL.
{% extends 'main/main.html' %}
{% block title %} Lista samochodów {% endblock %}
{% load static %}
{% block content %}
{% for carTEMP in cars %}
<div class="card bg-light mb-3">
<h5 class="card-header">
{{carTEMP}}
</h5>
<div class="card-body">
<img src="/media/{{carTEMP.car_photo}}">
<div class="row">
<div class="col-sm-auto">
<p>Data produkcji: {{carTEMP.car_date_of_prod}}</p>
<p>Numer rejestracyjny: {{carTEMP.car_registration_nr}}</p>
</div>
<div class="col-sm-auto">
<a href="{% url 'car_detailURL' carTEMP.id %}"><i class="fas fa-2x fa-info-circle"></i></a>
<a href="{% url 'edit_carURL' carTEMP.id %}"><i class="fas fa-2x fa-edit"></i></a>
<a href="{% url 'delete_carURL' carTEMP.id %}"><i class="fas fa-2x fa-trash-alt"></i></a>
</div>
</div>
</div>
</div>
{% endfor %}
{% include "main/pagination.html" with page=cars %}
{% endblock %}
And this is car_detail.html which I want to display in modal.
{% extends "main/main.html" %}
{% load static %}
{% block title %}
Szczególy
{% endblock %}
{% block content %}
<p><strong>Marka:</strong> {{ car.car_brand }}</p>
<p><strong>Model:</strong> {{ car.car_model }}</p>
<p><strong>Silnik:</strong> {{ car.car_engine }}</p>
<p><strong>Rok produkcji:</strong> {{ car.car_date_of_prod }}</p>
<p><strong>Numer rejestracyjny:</strong> {{ car.car_registration_nr }}</p>
{% endblock %}
And my views.py wiht car_detail view.
@login_required
def car_detail(request, id):
car = get_object_or_404(Car,
id=id,
car_available=True)
return render(request, 'cars/car_detail.html',
{'car': car})
And urls.py file:
from django.urls import path, include
from . import views
urlpatterns = [
path('all/', views.cars_list, name='cars_listURL'),
path('available/', views.cars_list_available, name='cars_list_availableURL'),
path('new/', views.new_car, name='new_carURL'),
path('edit/<int:id>/', views.edit_car, name='edit_carURL'),
path('delete/<int:id>/', views.delete_car, name='delete_carURL'),
path('<int:id>/', views.car_detail, name='car_detailURL')
]
I don't need ready-made solutions. Carrot will be fine too. I need advice in which direction I must go