diff --git a/projects/views.py b/projects/views.py index 0d1be9f..daad7ad 100644 --- a/projects/views.py +++ b/projects/views.py @@ -73,6 +73,20 @@ class ProjectUpdateView( model = Project form_class = ProjectForm + def get_initial(self): + """ + Add the auto_track value to form's initial values. + If any of the project's dependencies is set to auto_track, then + set auto_track to True (it will set all dependencies to auto_track). + If none of the dependencies are set to auto_track, then leave as + False (no change, no auto tracking) + """ + initial = super(ProjectUpdateView, self).get_initial() + auto_tracked_project_deps = self.object.projectdependency_set.filter( + auto_track=True) + initial['auto_track'] = any(auto_tracked_project_deps) + return initial + def get_success_url(self): return reverse("project_detail", kwargs={"pk": self.object.pk})