From 2948c1d20306d4e4b7fdad3dafefc8e14e1d0d4b Mon Sep 17 00:00:00 2001 From: Juni Weisteen Bjerde Date: Wed, 25 Sep 2024 22:36:33 +0200 Subject: [PATCH] Remove admin_comment from company --- .../fixtures/development_companies.yaml | 1 - .../0029_bdb_remove_admin_comment.py | 38 +++++++++++++++++++ lego/apps/companies/models.py | 1 - lego/apps/companies/serializers.py | 2 - 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 lego/apps/companies/migrations/0029_bdb_remove_admin_comment.py diff --git a/lego/apps/companies/fixtures/development_companies.yaml b/lego/apps/companies/fixtures/development_companies.yaml index c4f21f508..c085ea656 100644 --- a/lego/apps/companies/fixtures/development_companies.yaml +++ b/lego/apps/companies/fixtures/development_companies.yaml @@ -37,7 +37,6 @@ payment_mail: faktura@bekk.no address: Postboks 134 Sentrum, 0102 Oslo company_type: 'Konsulent, Data&Komtek' - admin_comment: 'Husk logo på alle sider' - model: companies.Company pk: 2 diff --git a/lego/apps/companies/migrations/0029_bdb_remove_admin_comment.py b/lego/apps/companies/migrations/0029_bdb_remove_admin_comment.py new file mode 100644 index 000000000..bb818365a --- /dev/null +++ b/lego/apps/companies/migrations/0029_bdb_remove_admin_comment.py @@ -0,0 +1,38 @@ +# Generated by Django 4.0.10 on 2024-09-25 18:53 + +from django.db import migrations +from django.conf import settings + + +def create_comment_with_old_admin_comment(apps, schema_editor): + Company = apps.get_model("companies", "Company") + Comment = apps.get_model("comments", "Comment") + CompanyContentType = apps.get_model("contenttypes", "ContentType").objects.get( + model="company" + ) + + for c in Company.objects.all(): + if c.admin_comment != None: + Comment.objects.create( + text="Autogenerert kommentar fra gammelt notat: \n" + c.admin_comment, + content_type=CompanyContentType, + object_id=c.id, + ) + + +class Migration(migrations.Migration): + + dependencies = [ + ('companies', '0028_alter_companyinterest_other_offers'), + ('comments', '0008_alter_comment_created_by_alter_comment_updated_by'), + ("contenttypes", "0002_remove_content_type_name"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.RunPython(create_comment_with_old_admin_comment), + migrations.RemoveField( + model_name="company", + name="admin_comment", + ), + ] diff --git a/lego/apps/companies/models.py b/lego/apps/companies/models.py index e97c830c4..a35990464 100644 --- a/lego/apps/companies/models.py +++ b/lego/apps/companies/models.py @@ -52,7 +52,6 @@ class Company(BasisModel): company_type = models.CharField(max_length=200, blank=True) website = models.URLField(blank=True) address = models.CharField(max_length=200, blank=True) - admin_comment = models.CharField(max_length=100, blank=True) active = models.BooleanField(default=True) payment_mail = models.EmailField(max_length=100, blank=True) comments = GenericRelation(Comment) diff --git a/lego/apps/companies/serializers.py b/lego/apps/companies/serializers.py index 3f978f47e..98c4458be 100644 --- a/lego/apps/companies/serializers.py +++ b/lego/apps/companies/serializers.py @@ -138,7 +138,6 @@ class Meta: "name", "semester_statuses", "student_contact", - "admin_comment", "active", ) @@ -203,7 +202,6 @@ class Meta: "content_target", "semester_statuses", "active", - "admin_comment", "logo", "files", "company_contacts",