delete from app_things where type = 'foo';
to delete a number of objects at once. I don't see a way to do this
type of delete in Django. I was hoping for something like:
things.delete(type__exact='foo')
Certainly I could do this:
for t in things.get_list(type__exact='foo'):
t.delete()
but this incurs a lot more database activity.
Have I overlooked something?
--Ned.
Nope - *we've* overlooked something; this totally should be
possible. I've opened a ticket so we can keep track of this (http://
code.djangoproject.com/ticket/1219).
Jacob
and, while on this note, check boxes in admin for bulk delete there
--
regards
kg
http://www.livejournal.com/users/lawgon
tally ho! http://avsap.org.in
ಇಂಡ್ಲಿನಕ್ಸ வாழ்க!
On Saturday 14 Jan 2006 1:11 am, Jacob Kaplan-Moss wrote:
> > Have I overlooked something?
>
> Nope - *we've* overlooked something; this totally should be
> possible. I've opened a ticket so we can keep track of this
> (http:// code.djangoproject.com/ticket/1219).
and, while on this note, check boxes in admin for bulk delete there
for id in checked:or something like that, which has nothing to do with "bulk delete" as being discussed in the ticket.
things.get_object(pk=id).delete()
As of having check boxes to select multiple item in admin views, I would much rather prefer "edit selected", where you can bulk edit items, delete being just one of the operations. Its like iTunes edit multiple song screenshot attached, for each field put a checkbox before that filed, and just try to imitate what iTunes does there. [May be put a little bit of ajax and have a togglable div displaying the current vaules of objects selected]. Please tell me if I am not being clear enough.
I think that's a good idea, but I'm worried about the behaviour of
things.delete() with no parameters: would it just delete all of the
things? Perhaps it should require that there is at least one
parameter.
--joey
I want to add one more item to the admin wish list: a button to clear
the whole cache, if any.
Thanks,
Eugene
I've just submitted a patch on magic-removal to this ticket that
implements bulk delete; the syntax is similar to that originally
proposed, except that the delete method is on the Manager, rather than
the class itself:
Things.objects.delete(type__exact='foo')
Any query that is legal for get_list() et al should be legal in
delete(), with the exception of anything requiring a join. DELETE FROM
foo INNER JOIN bar... isn't legal, so any query that requires a join
will cause the delete() to throw an exception.
Any objections to this commit? Or are the impending descriptor changes
going to render this patch immediately obsolete?
Russ Magee %-)
Russ Magee %-)
What happens if you call Something.objects.delete() without any
arguments? Does it delete every row from the table?
If so it might be useful to have some kind of "magic" keyword
argument which has to be used to achieve that. Having a method that
can nuke everything if you hit the wrong key makes me a little
nervous. Something like this perhaps:
Something.objects.delete(DELETE_ALL=True)
Calling the delete() method with no parameters could raise an error.
Cheers,
Simon
Why? Are you saying spontaneous accidental destruction of the entire
table would be a _bad_ thing? :-)
> Something.objects.delete(DELETE_ALL=True)
>
> Calling the delete() method with no parameters could raise an error.
Sounds good to me. Implemented, tested and committed, along with
documentation to explain the bulk delete call.
Russ Magee %-)
Hum. That's a _tad_ bit fast committing for me - just because nobody
commented on it doesn't say there aren't any comments on it in the
queue :-)
One problem I see is with related objects. When Django does a .delete()
on an object, it does delete related objects with it. And it deletes
especially used rows in relation tables (those that are behind the
ManyToMany machinery). Does your patch handle this? I don't think so -
so when using the bulk delete, there might be leftover related objects
that aren't deleted.
bye, Georg
Yeah, that's a tad bit fast for me, as well. A lack of comments
doesn't give consent.
> One problem I see is with related objects. When Django does a .delete()
> on an object, it does delete related objects with it. And it deletes
> especially used rows in relation tables (those that are behind the
> ManyToMany machinery). Does your patch handle this? I don't think so -
> so when using the bulk delete, there might be leftover related objects
> that aren't deleted.
The patch doesn't appear to handle this, which means we have
inconsistent behavior between bulk delete and normal deletion.
Adrian
--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org
On 1/18/06, hugo <g...@hugo.westfalen.de> wrote:
> >Ok; in the absence of any objections, I've just committed the change,
> >and closed off the ticket. Bulk delete is now available in
> >magic-removal.
>
> Hum. That's a _tad_ bit fast committing for me - just because nobody
> commented on it doesn't say there aren't any comments on it in the
> queue :-)
Yeah, that's a tad bit fast for me, as well. A lack of comments
doesn't give consent.
The patch doesn't appear to handle this, which means we have
inconsistent behavior between bulk delete and normal deletion.