39435-vm/core/migrations/0002_seed_demo_events.py
Flatlogic Bot 693107e079 v1
2026-04-02 16:02:38 +00:00

70 lines
2.5 KiB
Python

# Generated by Django 5.2.7 on 2026-04-02 14:57
import datetime
from django.db import migrations
from django.utils import timezone
def seed_events(apps, schema_editor):
Event = apps.get_model('core', 'Event')
if Event.objects.exists():
return
tz = timezone.get_current_timezone()
demo_events = [
{
'name': 'Spring Market Pop-Up',
'slug': 'spring-market-pop-up-2026-04-10',
'location': 'Riverfront Pavilion',
'start': timezone.make_aware(datetime.datetime(2026, 4, 10, 10, 0), tz),
'end': timezone.make_aware(datetime.datetime(2026, 4, 10, 15, 0), tz),
'event_url': 'https://example.com/events/spring-market-pop-up',
'summary': 'Browse seasonal specials, meet the team, and pick up limited weekend offers.',
'is_published': True,
},
{
'name': 'Neighborhood Food Fair',
'slug': 'neighborhood-food-fair-2026-04-16',
'location': 'Main Street Square',
'start': timezone.make_aware(datetime.datetime(2026, 4, 16, 11, 30), tz),
'end': timezone.make_aware(datetime.datetime(2026, 4, 16, 18, 0), tz),
'event_url': 'https://example.com/events/neighborhood-food-fair',
'summary': 'A full afternoon of tastings, live music, and a simple way for visitors to find your booth.',
'is_published': True,
},
{
'name': 'Weekend Makers Showcase',
'slug': 'weekend-makers-showcase-2026-04-25',
'location': 'Cedar Hall',
'start': timezone.make_aware(datetime.datetime(2026, 4, 25, 9, 0), tz),
'end': timezone.make_aware(datetime.datetime(2026, 4, 25, 14, 30), tz),
'event_url': 'https://example.com/events/weekend-makers-showcase',
'summary': 'An example public event showing how names, times, and external links appear in the widget.',
'is_published': True,
},
]
Event.objects.bulk_create([Event(**item) for item in demo_events])
def remove_seeded_events(apps, schema_editor):
Event = apps.get_model('core', 'Event')
Event.objects.filter(
slug__in=[
'spring-market-pop-up-2026-04-10',
'neighborhood-food-fair-2026-04-16',
'weekend-makers-showcase-2026-04-25',
]
).delete()
class Migration(migrations.Migration):
dependencies = [
('core', '0001_initial'),
]
operations = [
migrations.RunPython(seed_events, remove_seeded_events),
]