Skip to content

Commit 848b4fc

Browse files
committed
Only show not hidden photos
1 parent 21b3c56 commit 848b4fc

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

api/filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ReportFilter(filters.FilterSet):
5858

5959
def filter_has_photos(self, queryset, name, value):
6060
# Subquery to check for existence of related Photos
61-
return queryset.annotate(photo_exist=models.Exists(Photo.objects.filter(report=models.OuterRef('pk')))).filter(photo_exist=value)
61+
return queryset.annotate(photo_exist=models.Exists(Photo.objects.filter(report=models.OuterRef('pk'), hide=False))).filter(photo_exist=value)
6262

6363
class Meta:
6464
model = Report

api/views.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django.contrib.auth import get_user_model
2-
from django.db import transaction
2+
from django.db import models
33

44
from django_filters.rest_framework import DjangoFilterBackend
55
from drf_spectacular.utils import (
@@ -28,6 +28,7 @@
2828
Report,
2929
Fix,
3030
Notification,
31+
Photo
3132
)
3233

3334
from .filters import ReportFilter, NotificationFilter, CampaignFilter
@@ -145,7 +146,12 @@ class ReportViewSet(
145146
DestroyModelMixin,
146147
GenericViewSet,
147148
):
148-
queryset = Report.objects.prefetch_related("photos").non_deleted()
149+
queryset = Report.objects.prefetch_related(
150+
models.Prefetch(
151+
"photos",
152+
queryset=Photo.objects.filter(hide=False)
153+
)
154+
).non_deleted()
149155

150156
serializer_class = ReportSerializer
151157
lookup_url_kwarg = "uuid"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.2.7 on 2024-10-30 10:03
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('tigaserver_app', '0054_auto_20241025_1242'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='photo',
15+
name='hide',
16+
field=models.BooleanField(db_index=True, default=False, help_text='Hide this photo from public views?'),
17+
),
18+
]

tigaserver_app/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2858,7 +2858,7 @@ class Photo(models.Model):
28582858
photo = models.ImageField(upload_to=make_image_uuid, help_text='Photo uploaded by user.')
28592859
report = models.ForeignKey(Report, related_name='photos', help_text='Report and version to which this photo is associated (36-digit '
28602860
'report_UUID).', on_delete=models.CASCADE, )
2861-
hide = models.BooleanField(default=False, help_text='Hide this photo from public views?')
2861+
hide = models.BooleanField(default=False, help_text='Hide this photo from public views?', db_index=True)
28622862
uuid = models.CharField(max_length=36, default=make_uuid)
28632863
blood_genre = models.CharField(max_length=20, choices=BLOOD_GENRE, null=True, default=None)
28642864

0 commit comments

Comments
 (0)