Hello everybody

I have a model with self reference foreign key :

class Categories(Model.model):

    category = Model.CharField(...)
    parent_category = Model.ForeignKey(self, ...)
    url = Model.CharField(....)

an i want to remove items from this table given the url of a category
this is a peace of the table :

ID    category   id_parent_category url
1      blabla           NULL                NULL               #this
is a root category
2      blala            1                 http://www.blabla

know for removing the category of the url http://www.blabla i do like
this

category = Categories.objects.get(url = "http://www.blabla";)
category.delete()

but i want to remove also the parent category so i used the the
cascade deleting by default and i write in the model a function
delete_all() :

def delete_all():
     category = Categories.objects.get(url = "....")
     while category.parent_category :
           category = category.parent_category

     category.delete()

and i called like this :

category = Categories.objects.get(url = "http://www.blabla";)
category.delete_all()

the problem now it's that i have lot of categories in the table and
with this way it's take lot of time to remove them.

someone have a better idea to remove them , and sorry for this long
post

-- 
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.

Reply via email to