From d19cb8c6819ca9566e003172894d07c4847cb634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Thu, 22 Jul 2021 16:28:02 +0300 Subject: [PATCH] Add a data migration to populate Member.role --- hc/accounts/migrations/0041_fill_role.py | 20 ++++++++++++++++++++ hc/accounts/models.py | 4 +--- 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 hc/accounts/migrations/0041_fill_role.py diff --git a/hc/accounts/migrations/0041_fill_role.py b/hc/accounts/migrations/0041_fill_role.py new file mode 100644 index 00000000..487fde7b --- /dev/null +++ b/hc/accounts/migrations/0041_fill_role.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.4 on 2021-07-22 13:25 + +from django.db import migrations + + +def fill_member_role(apps, schema_editor): + Member = apps.get_model("accounts", "Member") + Member.objects.filter(rw=False).update(role="r") + Member.objects.filter(rw=True).update(role="w") + + +class Migration(migrations.Migration): + + dependencies = [ + ("accounts", "0040_auto_20210722_1244"), + ] + + operations = [ + migrations.RunPython(fill_member_role, migrations.RunPython.noop), + ] diff --git a/hc/accounts/models.py b/hc/accounts/models.py index 266a9a44..ff2b8877 100644 --- a/hc/accounts/models.py +++ b/hc/accounts/models.py @@ -428,9 +428,7 @@ class Member(models.Model): project = models.ForeignKey(Project, models.CASCADE) transfer_request_date = models.DateTimeField(null=True, blank=True) rw = models.BooleanField(default=True, null=True) - role = models.CharField( - max_length=1, default=Role.REGULAR, choices=Role.choices, blank=True, null=True - ) + role = models.CharField(max_length=1, default=Role.REGULAR, choices=Role.choices) class Meta: constraints = [