NDOJ/judge/migrations/0186_change_about_fields_max_len.py

44 lines
1.2 KiB
Python
Raw Permalink Normal View History

2024-04-12 17:09:40 +00:00
# Generated by Django 3.2.18 on 2024-04-12 17:04
from django.db import migrations, models
def truncate_about_text(apps, schema_editor):
Organization = apps.get_model("judge", "Organization")
Profile = apps.get_model("judge", "Profile")
for org in Organization.objects.all():
if len(org.about) > 10000:
org.about = org.about[:10000]
org.save()
for profile in Profile.objects.all():
if profile.about and len(profile.about) > 10000:
profile.about = profile.about[:10000]
profile.save()
class Migration(migrations.Migration):
dependencies = [
("judge", "0185_rename_org_profile_colum"),
]
operations = [
migrations.RunPython(truncate_about_text),
migrations.AlterField(
model_name="organization",
name="about",
field=models.CharField(
max_length=10000, verbose_name="organization description"
),
),
migrations.AlterField(
model_name="profile",
name="about",
field=models.CharField(
blank=True, max_length=10000, null=True, verbose_name="self-description"
),
),
]