From 08eef6408f2d221318de3b70242738d3a626710c Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Fri, 12 Apr 2024 12:09:40 -0500 Subject: [PATCH] Add text limit to about fields --- .../0186_change_about_fields_max_len.py | 43 +++++++++++++++++++ judge/models/profile.py | 8 +++- 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 judge/migrations/0186_change_about_fields_max_len.py diff --git a/judge/migrations/0186_change_about_fields_max_len.py b/judge/migrations/0186_change_about_fields_max_len.py new file mode 100644 index 0000000..9e8cf01 --- /dev/null +++ b/judge/migrations/0186_change_about_fields_max_len.py @@ -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" + ), + ), + ] diff --git a/judge/models/profile.py b/judge/models/profile.py index 7d3cf02..8975bb3 100644 --- a/judge/models/profile.py +++ b/judge/models/profile.py @@ -55,7 +55,9 @@ class Organization(models.Model): verbose_name=_("short name"), help_text=_("Displayed beside user name during contests"), ) - about = models.TextField(verbose_name=_("organization description")) + about = models.CharField( + max_length=10000, verbose_name=_("organization description") + ) registrant = models.ForeignKey( "Profile", verbose_name=_("registrant"), @@ -154,7 +156,9 @@ class Profile(models.Model): user = models.OneToOneField( User, verbose_name=_("user associated"), on_delete=models.CASCADE ) - about = models.TextField(verbose_name=_("self-description"), null=True, blank=True) + about = models.CharField( + max_length=10000, verbose_name=_("self-description"), null=True, blank=True + ) timezone = models.CharField( max_length=50, verbose_name=_("location"),