Monday, February 7, 2022

RE: Django ORM bug(probably, not)

Hi

try this

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

 

 

 

 

              

 

       

 

 

 

 

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of Bobosher Musurmonov
Sent: 07 February 2022 17:05
To: Django users
Subject: Django ORM bug(probably, not)

 

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

--
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+unsubscribe@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.

No comments:

Post a Comment