Commit 17d636a6 authored by Luis García's avatar Luis García
Browse files

Fix validate poll answers

parent 15a6402e
......@@ -29,18 +29,20 @@ class AnswerSerializer(ModelSerializer):
ref_name = 'Poll answer'
def validate(self, data):
in_valid = False
today = date.today()
user = self.context['request'].user
answers = Answer.objects.filter(
created__startswith=today,
question=data['question'],
response__owner=user
)
if answers.count() > 0:
in_valid = True
if in_valid:
raise ValidationError("You can't answer this question more than one time per day")
question = data['question']
if question.type == 'health':
in_valid = False
today = date.today()
user = self.context['request'].user
answers = Answer.objects.filter(
created__startswith=today,
question=question,
response__owner=user
)
if answers.count() > 0:
in_valid = True
if in_valid:
raise ValidationError("You can't answer this question more than one time per day")
return data
class ResponseSerializer(ModelSerializer):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment