I have models (simplified example):
class Group(models.Model):
name = models.CharField(max_length = 32)
class Person(models.Model):
group = models.ForeignKey(Group)
class Task(models.Model):
group = models.ForeignKey(Group)
people = models.ManyToManyField(Person)
def save(self, **kwargs):
ppl = Person.objects.all().filter(group = self.group)
for p in ppl:
self.people.add(p)
super(Task, self).save(**kwargs)
I want to assign the task to some group of people and add all persons who belong to that group as well, as some other people later (or remove particular person from the task). Obviously save won't be performed because object has no id when it wants to add many-to-many relationship objects. How to handle such situation? I tried saving just before adding people to task and then saving again but that didn't work.
regards
chriss