mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 13:17:50 +02:00
Add migrations md to html
This commit is contained in:
34
ram/roster/migrations/0011_md_to_html.py
Normal file
34
ram/roster/migrations/0011_md_to_html.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# Generated by Django 4.1 on 2022-08-24 15:30
|
||||
|
||||
import markdown
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def md_to_html(apps, schema_editor):
|
||||
fields = {
|
||||
'RollingStock': ['notes'],
|
||||
}
|
||||
|
||||
for m in fields.items():
|
||||
model = apps.get_model('roster', m[0])
|
||||
|
||||
for row in model.objects.all():
|
||||
for field in m[1]:
|
||||
field = getattr(row, field)
|
||||
field = markdown.markdown(field)
|
||||
|
||||
row.save(update_fields=m[1])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("roster", "0010_alter_rollingstock_notes"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
md_to_html,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
]
|
Reference in New Issue
Block a user