Add OrderStatus to Django admin with Russian translations
- Add OrderStatusAdmin to admin panel with custom display methods - Implement color preview, order badge, and order count displays - Protect system statuses from deletion and code modification - Add orders_count property to OrderStatus model - Create migration to translate status names to Russian - Use format_html for safe HTML rendering in admin 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
# Generated by Django 5.0.10 on 2025-11-13 14:19
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def update_status_names_to_russian(apps, schema_editor):
|
||||
"""Обновляем названия статусов на русский язык"""
|
||||
OrderStatus = apps.get_model('orders', 'OrderStatus')
|
||||
|
||||
status_translations = {
|
||||
'draft': 'Черновик',
|
||||
'new': 'Новый',
|
||||
'confirmed': 'Подтвережден',
|
||||
'in_assembly': 'В сборке',
|
||||
'in_delivery': 'В доставке',
|
||||
'completed': 'Выполнен',
|
||||
'return': 'Возврат',
|
||||
'cancelled': 'Отменен',
|
||||
}
|
||||
|
||||
for code, russian_name in status_translations.items():
|
||||
try:
|
||||
status = OrderStatus.objects.get(code=code)
|
||||
status.name = russian_name
|
||||
status.label = russian_name
|
||||
status.save()
|
||||
except OrderStatus.DoesNotExist:
|
||||
pass
|
||||
|
||||
|
||||
def reverse_status_names(apps, schema_editor):
|
||||
"""Откатываем названия статусов обратно на английский (для отката миграции)"""
|
||||
OrderStatus = apps.get_model('orders', 'OrderStatus')
|
||||
|
||||
status_translations = {
|
||||
'draft': 'Draft',
|
||||
'new': 'New',
|
||||
'confirmed': 'Confirmed',
|
||||
'in_assembly': 'In Assembly',
|
||||
'in_delivery': 'In Delivery',
|
||||
'completed': 'Completed',
|
||||
'return': 'Return',
|
||||
'cancelled': 'Cancelled',
|
||||
}
|
||||
|
||||
for code, english_name in status_translations.items():
|
||||
try:
|
||||
status = OrderStatus.objects.get(code=code)
|
||||
status.name = english_name
|
||||
status.label = english_name
|
||||
status.save()
|
||||
except OrderStatus.DoesNotExist:
|
||||
pass
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('orders', '0002_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(update_status_names_to_russian, reverse_status_names),
|
||||
]
|
||||
Reference in New Issue
Block a user