@@ -988,7 +988,7 @@ class ListEventSerializer(ModelSerializer):
988988 field_reports = MiniFieldReportSerializer (many = True , read_only = True )
989989 dtype = DisasterTypeSerializer (required = False )
990990 ifrc_severity_level_display = serializers .CharField (source = "get_ifrc_severity_level_display" , read_only = True )
991- active_deployments = serializers .SerializerMethodField ( )
991+ active_deployments = serializers .IntegerField ( read_only = True )
992992
993993 class Meta :
994994 model = Event
@@ -1019,15 +1019,17 @@ class Meta:
10191019 "active_deployments" ,
10201020 )
10211021
1022- def get_active_deployments (self , event ) -> int :
1023- now = timezone .now ()
1024- return Personnel .objects .filter (
1025- type = Personnel .TypeChoices .RR ,
1026- start_date__lt = now ,
1027- end_date__gt = now ,
1028- deployment__event_deployed_to = event ,
1029- is_active = True ,
1030- ).count ()
1022+
1023+ # Instead of the below method we use the queryset's annotate tag:
1024+ # def get_active_deployments(self, event) -> int:
1025+ # now = timezone.now()
1026+ # return Personnel.objects.filter(
1027+ # type=Personnel.TypeChoices.RR,
1028+ # start_date__lt=now,
1029+ # end_date__gt=now,
1030+ # deployment__event_deployed_to=event,
1031+ # is_active=True,
1032+ # ).count()
10311033
10321034
10331035class SurgeEventSerializer (ModelSerializer ):
@@ -1655,7 +1657,7 @@ def update(self, instance, validated_data):
16551657 return instance
16561658
16571659
1658- # Instead of the below method we use the serializer 's annotate tag:
1660+ # Instead of the below method we use the queryset 's annotate tag:
16591661# @staticmethod
16601662# def get_is_ifrc_admin(obj) -> bool:
16611663# return obj.groups.filter(name__iexact="IFRC Admins").exists()
0 commit comments