feat: replace color field with colors ManyToManyField in items model
All checks were successful
Build and Push Docker Image / build (push) Successful in 26s

- Updated `Item` model to use a ManyToManyField for colors, replacing the old ForeignKey relationship
- Modified templates to handle multiple color swatches in product details
- Updated admin for managing colors with `filter_horizontal`
- Adjusted views to prefetch related `colors` data for items
- Added migration to apply database changes
This commit is contained in:
2026-05-26 00:20:29 +02:00
parent c42d32c76b
commit af129309ab
5 changed files with 48 additions and 15 deletions

View File

@@ -56,16 +56,19 @@
</span>
</div>
{% if item.color %}
<div class="product-summary__swatches" aria-label="Цвет товара">
<span
class="product-summary__swatch product-summary__swatch--active"
style="background: {{ item.color.hex_code }};"
title="{{ item.color.name }}"
></span>
<span class="product-summary__color-name">{{ item.color.name }}</span>
{% with colors=item.colors.all %}
{% if colors %}
<div class="product-summary__swatches" aria-label="Цвета товара">
{% for color in colors %}
<span
class="product-summary__swatch"
style="background: {{ color.hex_code }};"
title="{{ color.name }}"
></span>
{% endfor %}
</div>
{% endif %}
{% endwith %}
{% if item.description %}
<div class="product-summary__description">{{ item.description|linebreaksbr }}</div>
@@ -101,3 +104,11 @@
{% include "_fragments/footer.html" %}
{% endblock %}
{% block add_js %}
<script>
document.addEventListener('DOMContentLoaded', function () {
Fancybox.bind('[data-fancybox="product-gallery"]');
});
</script>
{% endblock %}