From 408970f16ebff44965fa2dce013ef31b6145f0d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reynir=20Bj=C3=B6rnsson?= Date: Sat, 1 Mar 2025 13:50:21 +0000 Subject: [PATCH] Create subscription periods in bootstrap_dev_data (#78) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise the /admin/members/ endpoint fails. Related to #77. The README should also be updated to reflect that you should probably do the bootstrap_dev_data on first setup. Reviewed-on: https://git.data.coop/data.coop/membersystem/pulls/78 Reviewed-by: valberg Co-authored-by: Reynir Björnsson Co-committed-by: Reynir Björnsson --- .../management/commands/bootstrap_dev_data.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/utils/management/commands/bootstrap_dev_data.py b/src/utils/management/commands/bootstrap_dev_data.py index a1d04f8..e95476f 100644 --- a/src/utils/management/commands/bootstrap_dev_data.py +++ b/src/utils/management/commands/bootstrap_dev_data.py @@ -1,7 +1,11 @@ """Command to bootstrap development data.""" +from datetime import timedelta +from django.utils import timezone +from django.db.backends.postgresql.psycopg_any import DateRange from django.contrib.auth.models import User from django.core.management import BaseCommand +from membership.models import SubscriptionPeriod class Command(BaseCommand): @@ -16,6 +20,7 @@ class Command(BaseCommand): """Handle the command.""" self.create_superuser() self.create_normal_users() + self.create_subscription_periods() def create_superuser(self) -> None: """Create superuser.""" @@ -31,3 +36,13 @@ class Command(BaseCommand): for user in self.normal_users: user.set_password(user.username) user.save() + + def create_subscription_periods(self) -> None: + """Create subscription periods.""" + self.stdout.write("Creating subscription periods") + SubscriptionPeriod.objects.create( + period=DateRange(timezone.now().date() - timedelta(days=182), timezone.now().date() + timedelta(days=183)) + ) + SubscriptionPeriod.objects.create( + period=DateRange(timezone.now().date() + timedelta(days=183), timezone.now().date() + timedelta(days=365)) + )