I have two models, a Project and an Action:
class Project(models.Model):
name = models.CharField("Project Name", max_length=200, unique = True)
complete = models.BooleanField(default=False, verbose_name="Complete?")
class Action(models.Model):
name = models.CharField("Action Name", max_length=200)
project = models.ForeignKey(Project, blank=True, null=True, verbose_name="Project")
notes = models.TextField("Notes", blank=True)
complete = models.BooleanField(default=False, verbose_name="Complete?")
status = models.IntegerField("Action Status", choices = STATUS, default=0)
When a Project is marked as complete, I’d like all of it’s Actions to be marked as complete as well.
I’m trying to do this in the Project’s save method:
def save(self, **kw):
self.last_modified = datetime.today()
self.action.all().update(complete=True)
super(Project, self).save(**kw)
I’m stuck on that third line above. I’m not quite sure how to set all actions connected to this project to complete.
Inside the save method use…