Make completed tasks stay complete on save

This commit is contained in:
james1293 2019-08-05 15:41:42 -04:00 committed by GitHub
parent 2d40ef471e
commit 302906c4b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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