mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 03:17:07 +00:00
39
people/migrations/0044_themes_to_admin_question.py
Normal file
39
people/migrations/0044_themes_to_admin_question.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# Generated by Django 2.2.10 on 2021-03-10 09:05
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
from .utils.question_sets import port_question
|
||||
|
||||
|
||||
def migrate_forward(apps, schema_editor):
|
||||
# Make question
|
||||
Theme = apps.get_model('people', 'Theme')
|
||||
theme_question = port_question(
|
||||
apps, 'Research theme affiliation',
|
||||
Theme.objects.all().values_list('name', flat=True),
|
||||
is_multiple_choice=True)
|
||||
|
||||
PersonAnswerSet = apps.get_model('people', 'PersonAnswerSet')
|
||||
for answerset in PersonAnswerSet.objects.all():
|
||||
for theme in answerset.themes.all():
|
||||
answerset.question_answers.add(
|
||||
theme_question.answers.get(text=theme.name)
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('people', '0043_organisationanswerset_is_partner_organisation'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(migrate_forward),
|
||||
migrations.RemoveField(
|
||||
model_name='personanswerset',
|
||||
name='themes',
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='Theme',
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user