Добавил ссылки на продукты

This commit is contained in:
NikDizell 2026-06-19 16:47:59 +03:00
parent d4967bc4e5
commit afe0936b3e
2 changed files with 26 additions and 1 deletions

View File

@ -287,4 +287,8 @@
flex-direction: column;
align-items: flex-start;
}
}
.product-card {
cursor: pointer;
}

View File

@ -1,5 +1,6 @@
{% extends 'programmer/base.html' %}
{% load static %}
{% load django_bootstrap5 %}
{% block extra_css %}
{# Единый файл для CKEditor-контента (общий с блогом) #}
@ -38,7 +39,7 @@
{# ===== Сетка продуктов ===== #}
<div class="products-grid">
{% for product in products %}
<div class="product-card">
<div class="product-card" data-url="{{ product.get_absolute_url }}">
{% if product.image %}
<img src="{{ product.image.url }}" alt="{{ product.title }}" class="product-image" loading="lazy">
{% else %}
@ -85,3 +86,23 @@
{% include 'products/includes/pagination.html' %}
{% endblock %}
{% block extra_js %}
<script>
document.addEventListener('DOMContentLoaded', function() {
const cards = document.querySelectorAll('.product-card');
cards.forEach(card => {
const url = card.dataset.url;
if (!url) return;
card.addEventListener('click', function(e) {
// Если клик был по ссылке, кнопке или любому элементу с data-no-link
const target = e.target.closest('a, button, .no-link');
if (target) return;
window.location.href = url;
});
});
});
</script>
{% endblock %}