From 302906c4b41dfd8dfd2969853d9a78a3fe976820 Mon Sep 17 00:00:00 2001 From: james1293 Date: Mon, 5 Aug 2019 15:41:42 -0400 Subject: [PATCH] Make completed tasks stay complete on save --- todo/forms.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/todo/forms.py b/todo/forms.py index 072a201..0068bd1 100644 --- a/todo/forms.py +++ b/todo/forms.py @@ -53,6 +53,12 @@ class AddEditTaskForm(ModelForm): """Keep the existing created_by regardless of anything coming from the submitted form. If creating a new task, then created_by will be None, but we set it before saving.""" return self.instance.created_by + + def clean_completed(self): + """There's not a 'completed' checkbox on the edit form, + so Django assumes completed=False when you save. This function + disregards the form's `completed` value, so completed tasks stay complete.""" + return self.instance.completed class Meta: model = Task