diff --git a/bookwyrm/models/base_model.py b/bookwyrm/models/base_model.py index 06445a11d..d32ec67be 100644 --- a/bookwyrm/models/base_model.py +++ b/bookwyrm/models/base_model.py @@ -2,7 +2,7 @@ import base64 from Crypto import Random -from django.core.exceptions import PermissionDenied, FieldError +from django.core.exceptions import PermissionDenied from django.db import models from django.db.models import Q from django.dispatch import receiver @@ -120,12 +120,6 @@ class BookWyrmModel(models.Model): p for p in privacy_levels if not p in ["followers", "direct"] ] - # if there's a deleted field, exclude deleted items - try: - queryset = queryset.filter(deleted=False) - except FieldError: - pass - # exclude blocks from both directions if not viewer.is_anonymous: queryset = queryset.exclude( diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 3e5f638f5..1325aa884 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -6,6 +6,7 @@ from django.apps import apps from django.core.exceptions import PermissionDenied from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models +from django.db.models import Q from django.dispatch import receiver from django.template.loader import get_template from django.utils import timezone @@ -207,9 +208,14 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): if isinstance(self, (GeneratedNote, ReviewRating)): raise PermissionDenied() + @classmethod + def privacy_filter(cls, viewer, privacy_levels=None): + queryset = super().privacy_filter(viewer, privacy_levels=privacy_levels) + return queryset.filter(deleted=False) + @classmethod def direct_filter(cls, queryset, viewer): - """Override-able filter for "direct" privacy level""" + """Overridden filter for "direct" privacy level""" return queryset.exclude( ~Q(Q(user=viewer) | Q(mention_users=viewer)), privacy="direct" )