fix: Fix broken relationship update form

Did not get values from fields correctly
Incorrectly marked answersets as expired immediately
This commit is contained in:
James Graham
2020-04-20 13:30:15 +01:00
parent bf472a69fd
commit 719b11e79e
2 changed files with 5 additions and 9 deletions

View File

@@ -118,13 +118,12 @@ class RelationshipUpdateView(permissions.UserIsLinkedPersonMixin, CreateView):
"""
Mark any previous answer sets as replaced.
"""
previous_valid_answer_sets = self.relationship.answer_sets.filter(replaced_timestamp__isnull=True)
response = super().form_valid(form)
now_date = timezone.now().date()
# Shouldn't be more than one after initial updates after migration
for answer_set in previous_valid_answer_sets:
answer_set.replaced_timestamp = timezone.now()
for answer_set in self.relationship.answer_sets.exclude(pk=self.object.pk):
answer_set.replaced_timestamp = now_date
answer_set.save()
return response