32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
# Generated by Django 4.2.7 on 2025-12-19 08:59
|
|
|
|
from django.db import migrations
|
|
from decimal import Decimal
|
|
|
|
|
|
def populate_price_per_student(apps, schema_editor):
|
|
"""Заполняем price_per_student из существующих total_price и min_students."""
|
|
BulkDiscount = apps.get_model('subscriptions', 'BulkDiscount')
|
|
|
|
for discount in BulkDiscount.objects.all():
|
|
if discount.total_price and discount.min_students:
|
|
discount.price_per_student = discount.total_price / Decimal(str(discount.min_students))
|
|
discount.save()
|
|
|
|
|
|
def reverse_populate_price_per_student(apps, schema_editor):
|
|
"""Обратная операция - очищаем price_per_student."""
|
|
BulkDiscount = apps.get_model('subscriptions', 'BulkDiscount')
|
|
BulkDiscount.objects.all().update(price_per_student=None)
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('subscriptions', '0004_add_price_per_student_to_bulk_discount'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(populate_price_per_student, reverse_populate_price_per_student),
|
|
]
|