API: Fix selecting checkin question answers by option identifier

This commit is contained in:
Raphael Michel
2020-04-07 15:16:58 +02:00
parent 128a1f349a
commit 31fdf8721b
2 changed files with 29 additions and 3 deletions

View File

@@ -1116,10 +1116,13 @@ class Question(LoggedModel):
return None
if self.type == Question.TYPE_CHOICE:
try:
return self.options.get(Q(pk=answer) | Q(identifier=answer))
except:
q = Q(identifier=answer)
if answer.isdigit():
q |= Q(pk=answer)
o = self.options.filter(q).first()
if not o:
raise ValidationError(_('Invalid option selected.'))
return o
elif self.type == Question.TYPE_CHOICE_MULTIPLE:
if isinstance(answer, str):
l_ = list(self.options.filter(