On Fri, Apr 17, 2009 at 2:47 PM, koranthala <koranth...@gmail.com> wrote:

>
> Hi,
>    I am facing a problem which I believe should be a usual issue for
> everyone. But I cannot find a way to do it in a straightforward
> manner.
>   I have to select a list of items from table A and delete everyone
> of them. Now, there are close to 20K elements which I want to delete.
> So, what I do now is:
>    fields = tableA.filter(******)
>    for field in fields:
>      field.delete()
>
>   Now, this is invoking 20K separate messages to the DB - which is
> rather suboptimal. However I think, I could not find a mechanism to
> delete it in a straightway. One option I could think of is to create
> raw SQL and invoke - but I would like to do that as the last resort.
> Is there any other mechanism to do the same?
> >
>
tableA.objects.filter(...).delete()

Won't pull in each of the objects to delete them:
http://docs.djangoproject.com/en/dev/topics/db/queries/#topics-db-queries-delete

Alex
-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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