diff --git a/smartsoltech/web/admin.py b/smartsoltech/web/admin.py index 2b948c4..5bed2d0 100644 --- a/smartsoltech/web/admin.py +++ b/smartsoltech/web/admin.py @@ -59,15 +59,20 @@ class PortfolioImageInline(admin.TabularInline): @admin.register(PortfolioItem) class PortfolioItemAdmin(admin.ModelAdmin): - list_display = ('title', 'client_name', 'completion_date', 'featured', 'is_active', 'gallery_count') - list_filter = ('featured', 'is_active', 'completion_date', 'category') + list_display = ('title', 'client_name', 'completion_date', 'featured', 'is_active', 'gallery_count', 'categories_display') + list_filter = ('featured', 'is_active', 'completion_date', 'categories') search_fields = ('title', 'client_name', 'description') prepopulated_fields = {'slug': ('title',)} + filter_horizontal = ('categories',) inlines = [PortfolioImageInline] def gallery_count(self, obj): return obj.gallery_images.count() gallery_count.short_description = 'Фото в галерее' # type: ignore + + def categories_display(self, obj): + return ", ".join([cat.name for cat in obj.categories.all()[:3]]) + categories_display.short_description = 'Категории' # type: ignore @admin.register(NewsArticle) diff --git a/smartsoltech/web/models.py b/smartsoltech/web/models.py index 02cfbb9..f1c7f53 100644 --- a/smartsoltech/web/models.py +++ b/smartsoltech/web/models.py @@ -174,7 +174,7 @@ class PortfolioItem(models.Model): completion_date = models.DateField(blank=True, null=True) image = models.ImageField(upload_to='static/img/portfolio/', blank=True, null=True, verbose_name='Главное изображение') featured = models.BooleanField(default=False) - category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True, blank=True, related_name='portfolio_items') + categories = models.ManyToManyField(Category, blank=True, related_name='portfolio_items', verbose_name='Категории') is_active = models.BooleanField(default=True) class Meta: diff --git a/smartsoltech/web/templates/web/portfolio_detail.html b/smartsoltech/web/templates/web/portfolio_detail.html index b3911dc..2ed6b9a 100644 --- a/smartsoltech/web/templates/web/portfolio_detail.html +++ b/smartsoltech/web/templates/web/portfolio_detail.html @@ -7,12 +7,185 @@ {% endblock %} @@ -30,8 +203,12 @@
- {% if item.category %} - {{ item.category.name }} + {% if item.categories.all %} +
+ {% for category in item.categories.all %} + {{ category.name }} + {% endfor %} +
{% endif %}

{{ item.title }}

{% if item.client_name %} @@ -46,29 +223,58 @@ {% endif %}
- - {% if item.image %} -
- {{ item.title }} -
- {% endif %} - - - {% if item.gallery_images.all %} -
-

Галерея проекта

-
+ + {% if item.image or item.gallery_images.all %} + {% endif %} @@ -102,4 +308,119 @@ 'albumLabel': 'Изображение %1 из %2' }); + + + {% endblock %} diff --git a/smartsoltech/web/templates/web/portfolio_list.html b/smartsoltech/web/templates/web/portfolio_list.html index 31192da..2ef559f 100644 --- a/smartsoltech/web/templates/web/portfolio_list.html +++ b/smartsoltech/web/templates/web/portfolio_list.html @@ -47,8 +47,12 @@
{% endif %}
- {% if item.category %} - {{ item.category.name }} + {% if item.categories.all %} +
+ {% for category in item.categories.all %} + {{ category.name }} + {% endfor %} +
{% endif %}
{{ item.title }}
{% if item.client_name %} diff --git a/smartsoltech/web/views.py b/smartsoltech/web/views.py index 6194c58..7e40b90 100644 --- a/smartsoltech/web/views.py +++ b/smartsoltech/web/views.py @@ -412,10 +412,10 @@ def news_detail(request, slug): def portfolio_list(request): """Список всех активных элементов портфолио""" category_id = request.GET.get('category') - items = PortfolioItem.objects.filter(is_active=True) + items = PortfolioItem.objects.filter(is_active=True).prefetch_related('categories') if category_id: - items = items.filter(category_id=category_id) + items = items.filter(categories__id=category_id) categories = Category.objects.all() return render(request, 'web/portfolio_list.html', { @@ -426,7 +426,7 @@ def portfolio_list(request): def portfolio_detail(request, slug): """Детальная страница элемента портфолио""" - item = get_object_or_404(PortfolioItem, slug=slug, is_active=True) + item = get_object_or_404(PortfolioItem.objects.prefetch_related('categories', 'gallery_images'), slug=slug, is_active=True) return render(request, 'web/portfolio_detail.html', {'item': item})