Hi,

I have a File model with a ManyToManyField to 'self'. Which works
great, except that it's possible to add self to the parents (File 3
could add File 3 as a parent, causing an infinite relationship loop).
So i came up with a save() method which should remove self from the
parents before saving. But that does not seem to work.

Here's the relationship line in my File model:

parents = models.ManyToManyField('self', symmetrical=False,
related_name="child_set", null=True, blank=True,
filter_interface=models.HORIZONTAL)

with the following save method:

    def save(self):
        for p in self.parents.all():
            if int(p.id) == int(self.id):
                self.parents.remove(p)
                print self.parents.all()

        self.title = self.title.strip()
        if not self.id:
            self.created_at = datetime.today()
        self.updated_at = datetime.today()
        super(File, self).save()

The print self.parents.all() line does print a [] line with self
removed from the parents. Apparently this just does not get saved.

Any ideas?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to