-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: create flag and custom manager
- Loading branch information
1 parent
40a7e25
commit a5feb39
Showing
4 changed files
with
22 additions
and
141 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.db import models | ||
|
||
from .models import CommentModel | ||
|
||
|
||
class CommentManager(models.Manager): | ||
def soft_delete(self, instance: CommentModel): | ||
# if no children- hard delete | ||
if instance.children_count == 0: | ||
instance.delete() | ||
# else- soft delete | ||
else: | ||
instance.deleted = True | ||
instance.content = "[deleted]" | ||
instance.save() | ||
|
||
def clean_up_soft_deleted(self): | ||
self.filter(deleted=True, children_count=0).delete() |
This file contains 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
Empty file.
This file was deleted.
Oops, something went wrong.