Hello, Are you sure you don't have a cyclic reference in there:
cat1 -> cat2 -> cat1 ? You can always insert a import pdb; pdb.set_trace() line in the method and use the debugger to figure out what's keeping the loop from exiting normally. Nuno On Mon, Mar 29, 2010 at 2:55 PM, mouadino <mouad...@gmail.com> wrote: > hello everybody > > I have a model class where i m using a foreign key self-referencing > here is my code : > > class Categories(custom.Model): > url = models.ForeignKey(Urls, null=True, blank=True) > category = models.CharField(max_length=128) > parent_category = models.ForeignKey('self', null=True, blank=True) > > def delete_all(self): > """delete the parent category => deleting all sub categories > with the cascade delete""" > category = self > while category.parent_category: #the root category have the > parent_category NULL > category = category.parent_category > > > category.delete() > > > and when i m using the delete_all() with a sub category usually it > goes until the root category with the loop and should delete it with > all the sub categories because of the cascade delete . > > But when i m calling the delete_all() it's goes in an infinity loop . > > If someone can help me , and sorry for my English > > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.