1
1
from django_filters .rest_framework import DjangoFilterBackend
2
+ from rest_framework .request import Request
2
3
from rest_framework .filters import SearchFilter
3
4
from rest_framework .mixins import (
4
5
CreateModelMixin ,
@@ -113,6 +114,7 @@ class ReminderViewSet(
113
114
114
115
### DELETE /bot/reminders/<id:int>
115
116
Delete the reminder with the given `id`.
117
+ This is a soft-delete by setting `active` to False.
116
118
117
119
#### Status codes
118
120
- 204: returned on success
@@ -126,3 +128,19 @@ class ReminderViewSet(
126
128
queryset = Reminder .objects .prefetch_related ('author' )
127
129
filter_backends = (DjangoFilterBackend , SearchFilter )
128
130
filterset_fields = ('active' , 'author__id' )
131
+
132
+ def perform_destroy (self , instance : Reminder ) -> None :
133
+ """Soft-delete reminders when DELETE is called."""
134
+ instance .active = False
135
+ instance .save ()
136
+
137
+ def get_queryset (self ) -> list [Reminder ]:
138
+ """Filter out soft-deleted reminders by default."""
139
+ queryset = Reminder .objects .prefetch_related ('author' )
140
+ request : Request = self .request
141
+
142
+ include_inactive = request .query_params .get ("include_inactive" , "false" )
143
+ include_inactive = include_inactive .lower () == "true"
144
+ if not include_inactive :
145
+ queryset = queryset .filter (active = True )
146
+ return queryset
0 commit comments