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:
parent
b64779c780
commit
408970f16e
1 changed files with 15 additions and 0 deletions
|
@ -1,7 +1,11 @@
|
||||||
"""Command to bootstrap development data."""
|
"""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.contrib.auth.models import User
|
||||||
from django.core.management import BaseCommand
|
from django.core.management import BaseCommand
|
||||||
|
from membership.models import SubscriptionPeriod
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
@ -16,6 +20,7 @@ class Command(BaseCommand):
|
||||||
"""Handle the command."""
|
"""Handle the command."""
|
||||||
self.create_superuser()
|
self.create_superuser()
|
||||||
self.create_normal_users()
|
self.create_normal_users()
|
||||||
|
self.create_subscription_periods()
|
||||||
|
|
||||||
def create_superuser(self) -> None:
|
def create_superuser(self) -> None:
|
||||||
"""Create superuser."""
|
"""Create superuser."""
|
||||||
|
@ -31,3 +36,13 @@ class Command(BaseCommand):
|
||||||
for user in self.normal_users:
|
for user in self.normal_users:
|
||||||
user.set_password(user.username)
|
user.set_password(user.username)
|
||||||
user.save()
|
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))
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue