django - Cascading Delete w/ Custom Model Delete Method -
i have custom delete
method on model
make sure called correctly when calling delete
on queryset using: custom delete method on queryset.
this not seem work when django performs cascading delete. in case, orm calls _raw_delete
on regular queryset
thereby bypassing custom delete method.
how prevent happening?
the issue seems caused because uses _base_manager
rather _default_manager
:
def related_objects(self, related, objs): return related.related_model._base_manager.using(self.using).filter( **{"%s__in" % related.field.name: objs} )
it looks need add queryset
:
def _raw_delete(self, using): self.delete() _raw_delete.alters_data = true
and set use_for_related_fields = true
on manager
.
Comments
Post a Comment