我试图摆脱自制解决方案以支持更标准的解决方案。我之前的模式:
class MarkDeleteManager(models.Manager):
use_for_related_fields = True
def get_queryset(self):
if "instance" in self._hints:
return super(MarkDeleteManager, self).get_queryset()
return super(MarkDeleteManager, self).get_queryset().filter(deleted=False)
def all_with_deleted(self):
return super(MarkDeleteManager, self).get_queryset()
def deleted_set(self):
return super(MarkDeleteManager, self).get_queryset().filter(deleted=True)
def using(self, *args, **kwargs):
''' if a specific record was requested, return it even if it's deleted '''
return self.all_with_deleted().using(*args, **kwargs)
我想用 django-model-util's 替换它,SoftDeletableModel
但我没有看到任何all_with_deleted
类似的功能SoftDeletableManagerMixin
- 它只会覆盖get_queryset
,仅此而已。我的架构是分散的,当我通知其他节点有关软删除的信息时,我需要访问这些节点。