@@ -1054,14 +1054,20 @@ class Meta:
10541054 fields = "__all__"
10551055 read_only_fields = ("created_at" , "modified_at" )
10561056
1057- @staticmethod
1058- def get_document_url (obj ):
1059- if obj .appeal_document_id and (document := AppealDocument .objects .filter (id = obj .appeal_document_id ).first ()):
1057+ def _get_document (self , obj ):
1058+ if not obj .appeal_document_id :
1059+ return None
1060+ document_map = self .context .get ("appeal_documents_map" )
1061+ if document_map is not None :
1062+ return document_map .get (obj .appeal_document_id )
1063+ return AppealDocument .objects .filter (id = obj .appeal_document_id ).first ()
1064+
1065+ def get_document_url (self , obj ):
1066+ if document := self ._get_document (obj ):
10601067 return document .document_url
10611068
1062- @staticmethod
1063- def get_document_name (obj ):
1064- if obj .appeal_document_id and (document := AppealDocument .objects .filter (id = obj .appeal_document_id ).first ()):
1069+ def get_document_name (self , obj ):
1070+ if document := self ._get_document (obj ):
10651071 return document .name
10661072
10671073
@@ -1088,14 +1094,20 @@ class Meta:
10881094 )
10891095 exclude = ("learning" , "type" , "organization" , "sector" , "per_component" )
10901096
1091- @staticmethod
1092- def get_document_url (obj ):
1093- if obj .appeal_document_id and (document := AppealDocument .objects .filter (id = obj .appeal_document_id ).first ()):
1097+ def _get_document (self , obj ):
1098+ if not obj .appeal_document_id :
1099+ return None
1100+ document_map = self .context .get ("appeal_documents_map" )
1101+ if document_map is not None :
1102+ return document_map .get (obj .appeal_document_id )
1103+ return AppealDocument .objects .filter (id = obj .appeal_document_id ).first ()
1104+
1105+ def get_document_url (self , obj ):
1106+ if document := self ._get_document (obj ):
10941107 return document .document_url
10951108
1096- @staticmethod
1097- def get_document_name (obj ):
1098- if obj .appeal_document_id and (document := AppealDocument .objects .filter (id = obj .appeal_document_id ).first ()):
1109+ def get_document_name (self , obj ):
1110+ if document := self ._get_document (obj ):
10991111 return document .name
11001112
11011113
0 commit comments