Skip to content

Commit c61d975

Browse files
hc-sousacursoragent
andcommitted
feat(marketplace): seed default service categories per island
Without categories the listing form has nothing to select and provider creation rejects unknown slugs, so the module ships with 8 baseline categories for sao-miguel (data migration, reversible). Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 1e4ec18 commit c61d975

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""Seed default service categories for the São Miguel island.
2+
3+
Without categories the listing form has nothing to select and provider
4+
creation rejects unknown slugs, so the module ships with a sensible baseline.
5+
"""
6+
7+
from django.db import migrations
8+
9+
DEFAULT_CATEGORIES = [
10+
('transfers', 'Transfers & Táxi', '🚐'),
11+
('tours', 'Tours & Excursões', '🗺️'),
12+
('guides', 'Guias', '🧭'),
13+
('accommodation', 'Alojamento', '🏠'),
14+
('activities', 'Atividades', '🤿'),
15+
('food', 'Restauração', '🍽️'),
16+
('rentals', 'Aluguer', '🚗'),
17+
('other', 'Outros', '✨'),
18+
]
19+
20+
21+
def seed_categories(apps, schema_editor):
22+
Island = apps.get_model('tenancy', 'Island')
23+
ServiceCategory = apps.get_model('marketplace', 'ServiceCategory')
24+
for island in Island.objects.filter(key='sao-miguel'):
25+
for slug, name, icon in DEFAULT_CATEGORIES:
26+
ServiceCategory.objects.get_or_create(
27+
island=island,
28+
slug=slug,
29+
defaults={'name': name, 'icon': icon},
30+
)
31+
32+
33+
def remove_categories(apps, schema_editor):
34+
Island = apps.get_model('tenancy', 'Island')
35+
ServiceCategory = apps.get_model('marketplace', 'ServiceCategory')
36+
slugs = [slug for slug, _, _ in DEFAULT_CATEGORIES]
37+
for island in Island.objects.filter(key='sao-miguel'):
38+
ServiceCategory.objects.filter(island=island, slug__in=slugs).delete()
39+
40+
41+
class Migration(migrations.Migration):
42+
dependencies = [
43+
('marketplace', '0001_initial'),
44+
('tenancy', '0008_enable_marketplace_feature_flag'),
45+
]
46+
47+
operations = [
48+
migrations.RunPython(seed_categories, remove_categories),
49+
]

0 commit comments

Comments
 (0)