refactor: move disciplines to admin-question

Resolves #59
This commit is contained in:
James Graham
2021-02-15 15:29:47 +00:00
parent 0b1f303d62
commit 7021f05b67
6 changed files with 67 additions and 14 deletions

View File

@@ -1,21 +1,20 @@
import typing
from django.core.exceptions import ObjectDoesNotExist
def port_question(apps, question_text: str,
answers_text: typing.Iterable[str]):
def port_question(apps, question_text: str, answers_text: typing.Iterable[str],
**kwargs):
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)
text=question_text, version=prev_question.version + 1, **kwargs)
except ObjectDoesNotExist:
question = PersonQuestion.objects.create(text=question_text)
question = PersonQuestion.objects.create(text=question_text, **kwargs)
for answer_text in answers_text:
question.answers.get_or_create(text=answer_text)