File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33from apps .border .enums import LANE_TYPE
44from apps .border .models import BorderCrossing , BorderCrossingLanes
5- from django .db .models import Max
65from rest_framework import serializers
76
87
@@ -49,8 +48,8 @@ class Meta:
4948 )
5049
5150 def get_last_updated (self , obj ):
52- last_updated = obj .bordercrossinglanes_set .aggregate ( Max ( 'last_updated' ))[ 'last_updated__max' ]
53- return last_updated
51+ dates = [ lane . last_updated for lane in obj .bordercrossinglanes_set .all () if lane . last_updated ]
52+ return max ( dates ) if dates else None
5453
5554 def to_representation (self , instance ):
5655 representation = super ().to_representation (instance )
Original file line number Diff line number Diff line change 66
77
88class BorderCrossingAPI (CachedListModelMixin ):
9- queryset = BorderCrossing .objects .all ()
9+ queryset = BorderCrossing .objects .all (). prefetch_related ( "bordercrossinglanes_set" )
1010 serializer_class = BorderCrossingSerializer
1111 cache_key = CacheKey .BORDER_CROSSING_LIST
1212 cache_timeout = CacheTimeout .BORDER_CROSSING_LIST
You can’t perform that action at this time.
0 commit comments