Yes, Django stores all objects in a dict, and then deletes them one at a time. This is the reason why only unique elements are deleted because they iterate over them. This is from the Django Collector class, which collects models for removal:
self.data = SortedDict([(model, self.data[model]) for model in sorted_models])
and then:
# delete instances for model, instances in self.data.iteritems(): query = sql.DeleteQuery(model) pk_list = [obj.pk for obj in instances] query.delete_batch(pk_list, self.using)
As long as you override __hash__
your models, when the models are stored in the self.data file, only unique ones are saved and then deleted.
source share