Commit Graph

5 Commits

Author SHA1 Message Date
d92045c4c4 refactor: Создать базовый класс BaseProductEntity и реструктурировать Product/ProductKit
Основные изменения:

## Модели (models.py)
- Создан абстрактный класс BaseProductEntity с общими полями:
  * Идентификация: name, sku, slug
  * Описания: description, short_description (новое поле)
  * Статус: is_active, timestamps, soft delete
  * Managers: objects, all_objects, active

- Product:
  * Унаследован от BaseProductEntity
  * sale_price переименован в price (основная цена)
  * Добавлено новое поле sale_price (цена со скидкой, nullable)
  * Добавлено property actual_price

- ProductKit:
  * Унаследован от BaseProductEntity
  * fixed_price переименован в price (ручная цена)
  * pricing_method: 'fixed' → 'manual'
  * Добавлено поле sale_price (цена со скидкой)
  * Добавлено поле cost_price (nullable)
  * Добавлены properties: calculated_price, actual_price
  * Обновлен calculate_price_with_substitutions()

## Forms (forms.py)
- ProductForm: добавлено short_description, price, sale_price
- ProductKitForm: добавлено short_description, cost_price, price, sale_price

## Admin (admin.py)
- ProductAdmin: обновлены list_display и fieldsets с новыми полями
- ProductKitAdmin: добавлены fieldsets, метод get_price_display()

## Templates
- product_form.html: добавлены поля price, sale_price, short_description
- product_detail.html: показывает зачеркнутую цену + скидку + бейджик "Акция"
- product_list.html: отображение цен со скидкой и бейджиком "Акция"
- all_products_list.html: единообразное отображение цен
- productkit_detail.html: отображение скидок с бейджиком "Акция"

## API (api_views.py)
- Обновлены все endpoints для использования поля price вместо sale_price

Результат: единообразная архитектура с поддержкой скидок, DRY-принцип,
логичные названия полей, красивое отображение акций в UI.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-31 00:49:01 +03:00
a9b16bf212 feat: Implement safe soft delete and hard delete actions in admin
- Override Django's delete_selected action to enforce soft deletion
  (calls .delete() on each object instead of queryset.delete())
- Add hard_delete_selected action for safe permanent deletion
  - Checks for dangerous relations (KitItem, etc.) before deleting
  - Only allows deletion if no critical dependencies exist
  - Safely deletes photos from media/ folder by explicitly calling
    ProductPhoto.delete() which triggers ImageProcessor cleanup
- Add delete() and hard_delete() method overrides to ProductTag model
  (Product, ProductKit, ProductCategory already had these)
- Integrate all three actions into admin classes:
  ProductCategoryAdmin, ProductTagAdmin, ProductAdmin, ProductKitAdmin
- Add get_queryset() and get_deleted_status() methods to admin classes
  for proper soft delete support

Now when admin clicks "Delete":
1. Regular "Удалить" = soft delete (is_deleted=True, stays in DB)
2. "Безопасно удалить" = hard delete (only if no dependencies, removes from DB)
3. "Восстановить" = restores soft-deleted items

Fixes issue where items were hard-deleted from admin instead of soft-deleted.

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-22 22:31:57 +03:00
8f3d247c3c refactor: Simplify admin photo preview - remove grid display
- Keep only single photo preview per inline (large version 800x800)
- Removed all_versions_preview display from photo inlines
- Cleaner, more focused admin interface
- Confirmed all sizes are stored correctly:
  * Large (800x800) verified
  * Medium (400x400) verified
  * Originals verified
- Use large_url() for preview in admin (best quality/size balance)
2025-10-22 16:44:37 +03:00
2b6acc5564 feat: Implement comprehensive image storage and processing system
- Add ImageProcessor utility for automatic image resizing
  * Creates 4 versions: original, thumbnail (150x150), medium (400x400), large (800x800)
  * Uses LANCZOS algorithm for quality, JPEG quality 90 for optimization
  * Handles PNG transparency with white background
  * 90% file size reduction for thumbnails vs original

- Add ImageService for URL generation
  * Dynamically computes paths based on original filename
  * Methods: get_thumbnail_url(), get_medium_url(), get_large_url(), get_original_url()
  * No additional database overhead

- Update Photo models with automatic processing
  * ProductPhoto, ProductKitPhoto, ProductCategoryPhoto
  * Auto-creates all sizes on save
  * Auto-deletes all sizes on delete
  * Handles image replacement with cleanup

- Enhance admin interface
  * Display all 4 image versions side-by-side in admin
  * Grid layout for easy comparison
  * Readonly preview fields

- Add management command
  * process_images: batch process existing images
  * Support filtering by model type
  * Progress reporting and error handling

- Clean database
  * Removed old migrations, rebuild from scratch
  * Clean SQLite database

- Add comprehensive documentation
  * IMAGE_STORAGE_STRATEGY.md: full system architecture
  * QUICK_START_IMAGES.md: quick reference guide
  * IMAGE_SYSTEM_EXAMPLES.md: code examples for templates/views/API

Performance metrics:
  * Original: 6.1K
  * Medium: 2.9K (52% smaller)
  * Large: 5.6K (8% smaller)
  * Thumbnail: 438B (93% smaller)

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-22 16:09:15 +03:00
d78c43d9a9 Initial commit: Django inventory system 2025-10-22 01:11:06 +03:00