Skip to content

Commit e734fb6

Browse files
committed
add group to test teacher users
1 parent 46a77df commit e734fb6

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Generated by Django 5.0.12 on 2025-05-05 13:43
2+
3+
from django.db import migrations
4+
5+
6+
def add_fac_group_to_teacher_users(apps, schema_editor):
7+
User = apps.get_model("users", "User")
8+
Group = apps.get_model("auth", "Group")
9+
FACILITATOR_GRP_NAME = "Facilitator"
10+
facilitator_grp = Group.objects.create(name=FACILITATOR_GRP_NAME)
11+
12+
# Get all users who are teachers (role 'f')
13+
teachers = User.objects.filter(enrollment__role="f")
14+
15+
# Add the 'facilitator' group to each teacher
16+
for teacher in teachers:
17+
if not teacher.groups.filter(name=FACILITATOR_GRP_NAME).exists():
18+
teacher.groups.add(facilitator_grp)
19+
teacher.save()
20+
21+
22+
class Migration(migrations.Migration):
23+
24+
dependencies = [
25+
("thoughtswap", "0011_prompt_in_bank_20250505_0937"),
26+
]
27+
28+
operations = [
29+
migrations.RunPython(add_fac_group_to_teacher_users),
30+
]

0 commit comments

Comments
 (0)