make Selling.payment_method a SmallIntegerField

This commit is contained in:
imperosol
2025-11-19 19:56:21 +01:00
parent 2a5893aa79
commit 78fe4e52ca
8 changed files with 53 additions and 25 deletions

View File

@@ -4,9 +4,35 @@ from django.db import migrations, models
from django.db.migrations.state import StateApps
def migrate_payment_method(apps: StateApps, schema_editor):
Selling = apps.get_model("counter", "Selling")
Selling.objects.filter(payment_method_str="CARD").update(payment_method=1)
def migrate_payment_method_reverse(apps: StateApps, schema_editor):
Selling = apps.get_model("counter", "Selling")
Selling.objects.filter(payment_method=1).update(payment_method_str="CARD")
class Migration(migrations.Migration):
dependencies = [("counter", "0034_alter_selling_date_selling_date_month_idx")]
operations = [
migrations.RemoveField(model_name="selling", name="is_validated"),
migrations.RenameField(
model_name="selling",
old_name="payment_method",
new_name="payment_method_str",
),
migrations.AddField(
model_name="selling",
name="payment_method",
field=models.PositiveSmallIntegerField(
choices=[(0, "Sith account"), (1, "Credit card")],
default=0,
verbose_name="payment method",
),
),
migrations.RunPython(migrate_payment_method, migrate_payment_method_reverse),
migrations.RemoveField(model_name="selling", name="payment_method_str"),
]