refactor: migrate to question sets for person qs

This means we're starting to use the same system for person questions
as for relationship questions
This commit is contained in:
James Graham
2020-11-26 12:59:30 +00:00
parent a94db2713e
commit 5035b121a6
8 changed files with 304 additions and 31 deletions

View File

@@ -0,0 +1,23 @@
import typing
from django.core.exceptions import ObjectDoesNotExist
def port_question(apps, question_text: str,
answers_text: typing.Iterable[str]):
PersonQuestion = apps.get_model('people', 'PersonQuestion')
try:
prev_question = PersonQuestion.objects.filter(
text=question_text).latest('version')
question = PersonQuestion.objects.create(
text=question_text, version=prev_question.version + 1)
except ObjectDoesNotExist:
question = PersonQuestion.objects.create(text=question_text)
for answer_text in answers_text:
question.answers.get_or_create(text=answer_text)
return question