|
17 | 17 | from rest_framework import status |
18 | 18 | from rest_framework.decorators import action |
19 | 19 | from rest_framework.exceptions import ValidationError |
| 20 | +from rest_framework.filters import SearchFilter |
20 | 21 | from rest_framework.mixins import ( |
21 | 22 | CreateModelMixin, |
22 | 23 | ListModelMixin, |
@@ -238,11 +239,14 @@ class BaseReportViewSet( |
238 | 239 | "photos", |
239 | 240 | queryset=Photo.objects.visible() |
240 | 241 | ) |
| 242 | + ).annotate( |
| 243 | + pk_str=models.functions.Cast('pk', output_field=models.CharField()), |
241 | 244 | ).non_deleted().filter(point__isnull=False).order_by('-server_upload_time') |
242 | 245 |
|
243 | 246 | lookup_url_kwarg = "uuid" |
244 | 247 |
|
245 | | - filter_backends = (DjangoFilterBackend,) |
| 248 | + filter_backends = (DjangoFilterBackend, SearchFilter) |
| 249 | + search_fields = ("report_id", "pk_str") |
246 | 250 |
|
247 | 251 | permission_classes = (ReportPermissions,) |
248 | 252 |
|
@@ -535,9 +539,13 @@ class IdentificationTaskViewSet(RetrieveModelMixin, ListModelMixin, GenericNoMob |
535 | 539 | "report__photos", |
536 | 540 | queryset=Photo.objects.visible(), |
537 | 541 | ) |
| 542 | + ).annotate( |
| 543 | + pk_str=models.functions.Cast('pk', output_field=models.CharField()), |
538 | 544 | ) |
539 | 545 | serializer_class = IdentificationTaskSerializer |
540 | 546 | filterset_class = IdentificationTaskFilter |
| 547 | + filter_backends = (DjangoFilterBackend, SearchFilter) |
| 548 | + search_fields = ("report__report_id", "pk_str") |
541 | 549 | permission_classes = (IdentificationTaskPermissions | UserRolePermission,) |
542 | 550 |
|
543 | 551 | lookup_field = 'pk' |
@@ -678,9 +686,14 @@ class AnnotationViewSet(IdentificationTaskNestedAttribute, NestedViewSetMixin, L |
678 | 686 | report=models.OuterRef('report') |
679 | 687 | ) |
680 | 688 | ) |
| 689 | + ).annotate( |
| 690 | + report_pk_str=models.functions.Cast('report_id', output_field=models.CharField()), |
681 | 691 | ) |
| 692 | + |
682 | 693 | serializer_class = AnnotationSerializer |
| 694 | + filter_backends = (DjangoFilterBackend, SearchFilter) |
683 | 695 | filterset_class = AnnotationFilter |
| 696 | + search_fields = ("report_pk_str",) #NOTE: not filtering by 'report__report_id' because in not being shown in the response. |
684 | 697 | permission_classes = (AnnotationPermissions | UserRolePermission, ) |
685 | 698 |
|
686 | 699 | parent_lookup_kwargs = { |
@@ -736,7 +749,9 @@ def get_queryset(self): |
736 | 749 | class MyAnnotationViewSet(ListModelMixin, GenericNoMobileViewSet): |
737 | 750 | queryset = IdentificationTaskViewSet.AnnotationViewSet.queryset |
738 | 751 | serializer_class = IdentificationTaskViewSet.AnnotationViewSet.serializer_class |
| 752 | + filter_backends = IdentificationTaskViewSet.AnnotationViewSet.filter_backends |
739 | 753 | filterset_class = IdentificationTaskViewSet.AnnotationViewSet.filterset_class |
| 754 | + search_fields = IdentificationTaskViewSet.AnnotationViewSet.search_fields |
740 | 755 | permission_classes = (MyAnnotationPermissions, ) |
741 | 756 |
|
742 | 757 | lookup_field = 'pk' |
|
0 commit comments