47 lines
2.5 KiB
Python
47 lines
2.5 KiB
Python
from django.core.management.base import BaseCommand
|
|
from core.models import Property, Guest, Stay, Campaign
|
|
from django.utils import timezone
|
|
import datetime
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Seeds the database with sample data'
|
|
|
|
def handle(self, *args, **kwargs):
|
|
# Create Properties
|
|
p1, _ = Property.objects.get_or_create(name="Ocean View Apartment", address="123 Beach Blvd, Miami")
|
|
p2, _ = Property.objects.get_or_create(name="Mountain Cabin", address="456 Pine Rd, Aspen")
|
|
p3, _ = Property.objects.get_or_create(name="City Loft", address="789 Main St, New York")
|
|
|
|
# Create Guests
|
|
g1, _ = Guest.objects.get_or_create(first_name="John", last_name="Doe", email="john@example.com", phone="123-456-7890")
|
|
g2, _ = Guest.objects.get_or_create(first_name="Jane", last_name="Smith", email="jane@example.com", phone="987-654-3210")
|
|
g3, _ = Guest.objects.get_or_create(first_name="Alice", last_name="Johnson", email="alice@example.com")
|
|
|
|
# Create Stays
|
|
Stay.objects.get_or_create(guest=g1, property=p1, check_in=datetime.date(2025, 1, 10), check_out=datetime.date(2025, 1, 15))
|
|
Stay.objects.get_or_create(guest=g2, property=p2, check_in=datetime.date(2025, 2, 1), check_out=datetime.date(2025, 2, 10))
|
|
Stay.objects.get_or_create(guest=g3, property=p3, check_in=datetime.date(2025, 2, 5), check_out=datetime.date(2025, 2, 12))
|
|
Stay.objects.get_or_create(guest=g1, property=p3, check_in=datetime.date(2026, 1, 5), check_out=datetime.date(2026, 1, 10))
|
|
|
|
# Create Campaigns
|
|
Campaign.objects.get_or_create(
|
|
title="Spring Discount Offer",
|
|
subject="Special 20% Off Your Next Stay!",
|
|
body="<h1>Spring is here!</h1><p>We'd love to have you back. Use code SPRING20 for 20% off your next booking at any of our properties.</p>",
|
|
status='draft'
|
|
)
|
|
Campaign.objects.get_or_create(
|
|
title="Refer a Friend Program",
|
|
subject="Share the Love, Get a Reward",
|
|
body="<p>Refer a friend to our apartments and get $50 credit for your next stay!</p>",
|
|
status='draft'
|
|
)
|
|
Campaign.objects.get_or_create(
|
|
title="Welcome Back",
|
|
subject="We missed you!",
|
|
body="<p>It's been a while since your last stay. Come visit us again soon!</p>",
|
|
status='sent',
|
|
sent_at=timezone.now() - datetime.timedelta(days=30)
|
|
)
|
|
|
|
self.stdout.write(self.style.SUCCESS('Successfully seeded sample data including campaigns')) |