I have a model: class Employee(models.Model): name = models.CharField(maxlength = 100) reportsTo = models.ForeignKey('self', null=True, related_name='dependent_element') subordinates = models.ManyToManyField('self')
I want to add the employee as a subordinate when the manager is defined, so long as they don't already exist: if manager.subordinates.filter(id = employee.id).count() == 0: manager.subordinates.add(employee) But this doesn't work ... it always returns count = 0. I think the problem is I'm attempting to ask "Give me the count of all of the subordinates of <this manager> where subordinate ID = employee ID" but what I'm actually asking is: "Give me the count of all of the subordinates of <this manager> where subordinate join table ID = employee ID" How should I phrase this? I couldn't see the answer in the archives (closest was http://groups.google.ca/group/django-users/browse_thread/thread/af75f41acda01ae5/5ac9f540627d4573?lnk=gst&q=many+to+many+self&rnum=1#5ac9f540627d4573) Thx Sandy --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---