Check if the current user has dismissed this notification.
(self, obj)
| 165 | read_only_fields = ['created_at'] |
| 166 | |
| 167 | def get_is_dismissed(self, obj): |
| 168 | """Check if the current user has dismissed this notification.""" |
| 169 | request = self.context.get('request') |
| 170 | if request and request.user.is_authenticated: |
| 171 | return obj.dismissals.filter(user=request.user).exists() |
| 172 | return False |
| 173 | |
| 174 | |
| 175 | class NotificationDismissalSerializer(serializers.ModelSerializer): |