Files
django-ram/ram/roster/migrations/0030_rollingstock_price.py
Daniele Viganò 026ab06354 Add a CSV export functionality in admin and add price fields (#41)
* Implement an action do download data in csv
* Refactor CSV download
* Move price to main models and add csv to bookshelf
* Update template and API
* Small refactoring
2024-12-29 21:46:57 +01:00

37 lines
971 B
Python

# Generated by Django 5.1.4 on 2024-12-29 15:23
from django.db import migrations, models
def price_to_property(apps, schema_editor):
rollingstock = apps.get_model("roster", "RollingStock")
for row in rollingstock.objects.all():
prop = row.property.filter(property__name__icontains="price")
for p in prop:
try:
row.price = float(p.value)
except ValueError:
pass
row.save()
class Migration(migrations.Migration):
dependencies = [
("roster", "0029_alter_rollingstockimage_options"),
]
operations = [
migrations.AddField(
model_name="rollingstock",
name="price",
field=models.DecimalField(
blank=True, decimal_places=2, max_digits=10, null=True
),
),
migrations.RunPython(
price_to_property,
reverse_code=migrations.RunPython.noop
),
]