On 7/19/06, Le Roux <[EMAIL PROTECTED]> wrote:

If I do something like MyModel.objects.filter(id__in=[1, 2,
3]).delete(), it doesn't look like the Model instances'  delete()
method will get called. I have some uploaded files that have a
corresponding File model that stores metadata related to files. I was
considering overriding the delete() method in the model to delete the
associated file(s), but it looks like that won't cut it.

Bulk delete and individual delete are quite separate mechanisms (although they do share some internal implementation). This is because the model delete call invokes an SQL 'DELETE FROM table WHERE pk=value" call - if you were to delete 1000 objects, you don't want to make 1000 such SQL requests - its faster to make one call to "DELETE FROM table WHERE pk in [1,2,3...]"

As a result, overriding the models delete() method will have no effect on the behaviour observed during a bulk delete.

If there's no easy way to override the bulk delete, is there at least a
way to stop the QuerySet's delete from executing?

Don't call it :-)

Seriously, I'm a little unclear what you're trying to do here; it sounds like what you want is:

[obj.delete() for obj in MyModel.objects.filter(id__in=[1, 2, 3])]

Does that do what you want, or am I missing something here?

Russ Magee %-)

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

Reply via email to