'Override save method to check for Milestone-Project links and auto-Status child Tasks'

def save(self, *args, **kwargs):

    original = None
    if self.id:
        original = Task.objects.get(pk=self.id)
        if (self.project_id != original.project_id):
            if (self.milestone_id and (self.milestone.project_id != self.project_id)):
                self.milestone = None
        elif (self.milestone_id and (self.milestone_id != original.milestone_id)):
            if (self.milestone.project_id != self.project_id):
                self.project_id = self.milestone.project_id
        if (self.status_id != original.status_id):
            if self.status.hidden:
                for task in self.child_set.exclude(status=self.status):
                    task.status_id = self.status_id
                    task.save()
                for slot in self.tasktimeslot_set.filter(time_to__isnull=True):
                    slot.time_to = datetime.now()
                    slot.save()
    elif (self.milestone_id and (self.milestone.project_id != self.project_id)):
        self.project_id = self.milestone.project_id
    if self.parent_id:
        if (self.project_id != self.parent.project_id):
            self.project_id = self.parent.project_id
        if (self.milestone_id != self.parent.milestone_id):
            self.milestone_id = self.parent.milestone_id
    super(Task, self).save(*args, **kwargs)
