Django ORM bug(probably, not)

24 views
Skip to first unread message

Bobosher Musurmonov

unread,
Feb 7, 2022, 9:11:41 AM2/7/22
to Django users
Hello, I have overloaded delete() method of my model to enable soft deletion so that delete() method just sets is_seleted field to be True.
When calling this method for individual objects, it works fine.
But when I called delete() method directly for a queryset (for example, MyModel.objects.filter(id__lte=10).delete(), it just hard-deleted those objects and not called my custom delete() method.

Please, let me know if it's a bug or not.
If it isn't, please let me know how to do this in a better way.
Now, my temporary solution is iterating through selected objects and call delete() method for each.

I've tested this on 2 versions of django: 1.11 and 3.2

Feroz Ahmed

unread,
Feb 7, 2022, 5:45:53 PM2/7/22
to django...@googlegroups.com

Hi

try this

MyObject.objects.filter(id__lte=10[i.id for i in objects_to_delete]).delete()

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6db418c3-3c65-400f-bd6c-d89bc1c4aab2n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages