Fix Docker setup: add gunicorn, fix permissions, update docker-compose and entrypoint, add deployment instructions
This commit is contained in:
@@ -161,10 +161,14 @@ class ProductDetailView(LoginRequiredMixin, ManagerOwnerRequiredMixin, DetailVie
|
||||
context_object_name = 'product'
|
||||
|
||||
def get_queryset(self):
|
||||
# Предзагрузка фотографий и аннотация остатков
|
||||
# Предзагрузка фотографий, категорий, тегов и аннотация остатков
|
||||
total_available = Coalesce(Sum('stocks__quantity_available'), Value(0), output_field=DecimalField())
|
||||
total_reserved = Coalesce(Sum('stocks__quantity_reserved'), Value(0), output_field=DecimalField())
|
||||
return super().get_queryset().prefetch_related('photos').annotate(
|
||||
return super().get_queryset().prefetch_related(
|
||||
'photos',
|
||||
'categories',
|
||||
'tags'
|
||||
).annotate(
|
||||
total_available=total_available,
|
||||
total_reserved=total_reserved,
|
||||
total_free=total_available - total_reserved,
|
||||
@@ -172,9 +176,16 @@ class ProductDetailView(LoginRequiredMixin, ManagerOwnerRequiredMixin, DetailVie
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
# Добавляем фотографии товара в контекст
|
||||
context['product_photos'] = self.object.photos.all().order_by('order', 'created_at')
|
||||
context['photos_count'] = self.object.photos.count()
|
||||
# Добавляем фотографии товара в контекст (используем уже загруженные через prefetch_related)
|
||||
product_photos = list(self.object.photos.all())
|
||||
product_photos.sort(key=lambda x: (x.order, x.created_at))
|
||||
context['product_photos'] = product_photos
|
||||
context['photos_count'] = len(product_photos)
|
||||
|
||||
# Кешируем cost_price_details, чтобы не делать множественные запросы к БД
|
||||
from ..services.cost_calculator import ProductCostCalculator
|
||||
context['cost_price_details'] = ProductCostCalculator.get_cost_details(self.object)
|
||||
|
||||
return context
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user