Create subscription periods in bootstrap_dev_data (#78)

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 <valberg@orn.li>
Co-authored-by: Reynir Björnsson <reynir@reynir.dk>
Co-committed-by: Reynir Björnsson <reynir@reynir.dk>
This commit is contained in:
Reynir Björnsson 2025-03-01 13:50:21 +00:00 committed by valberg
parent b64779c780
commit 408970f16e

View file

@ -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))
)