From 1e24bf9e5084c44beefd89ec108e619ff7a812c4 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Tue, 26 Sep 2023 10:08:30 +0200 Subject: [PATCH 1/2] Tender.siae_transactioned allow null (to seperate true & false) --- .../0057_alter_tender_siae_transactioned.py | 22 +++++++++++++++++++ lemarche/tenders/models.py | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 lemarche/tenders/migrations/0057_alter_tender_siae_transactioned.py diff --git a/lemarche/tenders/migrations/0057_alter_tender_siae_transactioned.py b/lemarche/tenders/migrations/0057_alter_tender_siae_transactioned.py new file mode 100644 index 000000000..2399f9200 --- /dev/null +++ b/lemarche/tenders/migrations/0057_alter_tender_siae_transactioned.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.2 on 2023-09-26 08:05 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("tenders", "0056_alter_tender_scale_marche_useless"), + ] + + operations = [ + migrations.AlterField( + model_name="tender", + name="siae_transactioned", + field=models.BooleanField( + blank=True, + help_text="Champ renseigné par un ADMIN", + null=True, + verbose_name="Abouti à une transaction avec une structure", + ), + ), + ] diff --git a/lemarche/tenders/models.py b/lemarche/tenders/models.py index a85ba0f47..3a75491c2 100644 --- a/lemarche/tenders/models.py +++ b/lemarche/tenders/models.py @@ -365,7 +365,8 @@ class Tender(models.Model): siae_transactioned = models.BooleanField( verbose_name="Abouti à une transaction avec une structure", help_text="Champ renseigné par un ADMIN", - default=False, + blank=True, + null=True, ) amount_exact = models.PositiveIntegerField( verbose_name="Montant exact du besoin", help_text="Champ renseigné par un ADMIN", blank=True, null=True From 446437c7bc65f54e904d7c943e134ac62859d12d Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Tue, 26 Sep 2023 10:25:17 +0200 Subject: [PATCH 2/2] Init command in migration --- .../migrations/0057_alter_tender_siae_transactioned.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lemarche/tenders/migrations/0057_alter_tender_siae_transactioned.py b/lemarche/tenders/migrations/0057_alter_tender_siae_transactioned.py index 2399f9200..d53d06f1c 100644 --- a/lemarche/tenders/migrations/0057_alter_tender_siae_transactioned.py +++ b/lemarche/tenders/migrations/0057_alter_tender_siae_transactioned.py @@ -3,6 +3,13 @@ from django.db import migrations, models +def set_siae_transactioned_false_to_null(apps, schema_editor): + Tender = apps.get_model("tenders", "Tender") + for tender in Tender.objects.filter(siae_transactioned=False, survey_transactioned_answer=None): + tender.siae_transactioned = None + tender.save(update_fields=["siae_transactioned"]) + + class Migration(migrations.Migration): dependencies = [ ("tenders", "0056_alter_tender_scale_marche_useless"), @@ -19,4 +26,5 @@ class Migration(migrations.Migration): verbose_name="Abouti à une transaction avec une structure", ), ), + migrations.RunPython(code=set_siae_transactioned_false_to_null), ]