Last active
July 19, 2018 18:50
-
-
Save i/a3e6582af834415aa1392da0bcd71cc5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SoftDeleteQuerySet(models.QuerySet): | |
@transaction.atomic | |
def delete(self, snapshot_id=None): | |
[x.delete(snapshot_id=snapshot_id) for x in self] | |
class SoftDeleteQueryManager(models.Manager): | |
def __init__(self, *args, **kwargs): | |
self.with_deleted = kwargs.pop('with_deleted', False) | |
super(SoftDeleteManager, self).__init__(*args, **kwargs) | |
# same fields and methods before except for | |
def get_queryset(self): | |
qs = SoftDeleteQuerySet(self.model) | |
if self.with_deleted: | |
return qs | |
return qs.filter(is_deleted=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment