feat: add subcategory support for catalog and admin
All checks were successful
Build and Push Docker Image / build (push) Successful in 30s
All checks were successful
Build and Push Docker Image / build (push) Successful in 30s
- Introduced `Subcategory` model with migration and unique slug constraint per category - Enabled subcategory assignment for items with validation to ensure category matching - Updated catalog views to handle subcategories, filtering items accordingly - Enhanced templates (`index.html`, `side-bar.html`, `item-list.html`, `detail.html`) to display subcategories - Added dynamic subcategory dropdown in Django admin with category filtering - Created JavaScript for admin subcategory handling and AJAX population - Wrote comprehensive tests for subcategory functionality in views and admin
This commit is contained in:
@@ -14,7 +14,9 @@
|
||||
{% endwith %}
|
||||
|
||||
<div class="item-card-body">
|
||||
<div class="item-card-category">{{ item.category.name }}</div>
|
||||
<div class="item-card-category">
|
||||
{{ item.category.name }}{% if item.subcategory %} / {{ item.subcategory.name }}{% endif %}
|
||||
</div>
|
||||
<h2 class="item-card-title">{{ item.name }}</h2>
|
||||
<div class="item-card-footer">
|
||||
<span class="item-card-price">{{ item.price }} руб.</span>
|
||||
|
||||
@@ -13,6 +13,20 @@
|
||||
|
||||
<section class="sub-categories a-section">
|
||||
<h2>Подкатегории</h2>
|
||||
{% if selected_category.id != None %}
|
||||
<a href="/catalog/{{ selected_category.id }}/" class="category {% if selected_subcategory.id == None %}active{% endif %}">
|
||||
Все подкатегории
|
||||
</a>
|
||||
{% for subcategory in subcategories %}
|
||||
<a href="/catalog/{{ selected_category.id }}/?subcategory={{ subcategory.slug }}" class="category {% if selected_subcategory.id == subcategory.slug %}active{% endif %}">
|
||||
{{ subcategory.name }}
|
||||
</a>
|
||||
{% empty %}
|
||||
<p class="categories-empty">Подкатегории пока не добавлены.</p>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<p class="categories-empty">Выберите категорию.</p>
|
||||
{% endif %}
|
||||
</section>
|
||||
|
||||
<form action="">
|
||||
|
||||
@@ -37,7 +37,9 @@
|
||||
</section>
|
||||
|
||||
<section class="product-summary" aria-label="Информация о товаре">
|
||||
<p class="product-summary__category">{{ item.category.name }}</p>
|
||||
<p class="product-summary__category">
|
||||
{{ item.category.name }}{% if item.subcategory %} / {{ item.subcategory.name }}{% endif %}
|
||||
</p>
|
||||
<h1 class="product-summary__title">{{ item.name }}</h1>
|
||||
|
||||
<div class="product-summary__meta">
|
||||
|
||||
@@ -13,12 +13,18 @@
|
||||
|
||||
{% if selected_category.id == None %}
|
||||
{% include '_fragments/breadcrumbs.html' with url_1='/' text_1='Главная' url_2='/catalog/' text_2='Каталог' %}
|
||||
{% elif selected_subcategory.id != None %}
|
||||
{% with category_url='/catalog/'|add:selected_category.id|add:'/' subcategory_url='/catalog/'|add:selected_category.id|add:'/?subcategory='|add:selected_subcategory.id %}
|
||||
{% include '_fragments/breadcrumbs.html' with url_1='/' text_1='Главная' url_2='/catalog/' text_2='Каталог' url_3=category_url text_3=selected_category.name url_4=subcategory_url text_4=selected_subcategory.name %}
|
||||
{% endwith %}
|
||||
{% else %}
|
||||
{% include '_fragments/breadcrumbs.html' with url_1='/' text_1='Главная' url_2='/catalog/' text_2='Каталог' text_3=selected_category.name %}
|
||||
{% with category_url='/catalog/'|add:selected_category.id|add:'/' %}
|
||||
{% include '_fragments/breadcrumbs.html' with url_1='/' text_1='Главная' url_2='/catalog/' text_2='Каталог' url_3=category_url text_3=selected_category.name %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
||||
<div class="container catalog-container">
|
||||
{% include 'catalog/_fragments/side-bar.html' with categories=categories selected_category=selected_category %}
|
||||
{% include 'catalog/_fragments/side-bar.html' with categories=categories subcategories=subcategories selected_category=selected_category selected_subcategory=selected_subcategory %}
|
||||
|
||||
{% include 'catalog/_fragments/item-list.html' with items=items %}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user