Add text limit to about fields
This commit is contained in:
parent
208a4e4ef7
commit
08eef6408f
2 changed files with 49 additions and 2 deletions
43
judge/migrations/0186_change_about_fields_max_len.py
Normal file
43
judge/migrations/0186_change_about_fields_max_len.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
# 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"
|
||||
),
|
||||
),
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue