@@ -59,8 +59,66 @@ class PlannedInterventionAdmin(ReadOnlyMixin, admin.ModelAdmin):
5959
6060@admin .register (DrefFile )
6161class DrefFileAdmin (admin .ModelAdmin ):
62+ list_display = ("id" , "file" , "appeal_code" )
6263 search_fields = ("file" ,)
6364
65+ def get_queryset (self , request ):
66+ return (
67+ super ()
68+ .get_queryset (request )
69+ .prefetch_related (
70+ "event_map_dref" ,
71+ "image_dref" ,
72+ "budget_file_dref" ,
73+ "dref_assessment_report" ,
74+ "dref_supporting_document" ,
75+ "cover_image_dref" ,
76+ "dref_scenario_supporting_document" ,
77+ "dref_contingency_plans_supporting_document" ,
78+ "event_map_dref_operational_update" ,
79+ "image_dref_operational_update" ,
80+ "cover_image_dref_operational_update" ,
81+ "budget_file_dref_operational_update" ,
82+ "dref_operational_update_assessment_report" ,
83+ "photos_dref_operational_update" ,
84+ "event_map_dref_final_report" ,
85+ "photos_dref_final_report" ,
86+ "dref_final_report_assessment_report" ,
87+ "image_dref_final_report" ,
88+ "cover_image_dref_final_report" ,
89+ )
90+ )
91+
92+ @admin .display (description = "Appeal Code" )
93+ def appeal_code (self , obj ):
94+ related_codes = set ()
95+ related_querysets = (
96+ obj .event_map_dref .all (),
97+ obj .image_dref .all (),
98+ obj .budget_file_dref .all (),
99+ obj .dref_assessment_report .all (),
100+ obj .dref_supporting_document .all (),
101+ obj .cover_image_dref .all (),
102+ obj .dref_scenario_supporting_document .all (),
103+ obj .dref_contingency_plans_supporting_document .all (),
104+ obj .event_map_dref_operational_update .all (),
105+ obj .image_dref_operational_update .all (),
106+ obj .cover_image_dref_operational_update .all (),
107+ obj .budget_file_dref_operational_update .all (),
108+ obj .dref_operational_update_assessment_report .all (),
109+ obj .photos_dref_operational_update .all (),
110+ obj .event_map_dref_final_report .all (),
111+ obj .photos_dref_final_report .all (),
112+ obj .dref_final_report_assessment_report .all (),
113+ obj .image_dref_final_report .all (),
114+ obj .cover_image_dref_final_report .all (),
115+ )
116+
117+ for queryset in related_querysets :
118+ related_codes .update (filter (None , queryset .values_list ("appeal_code" , flat = True )))
119+
120+ return ", " .join (sorted (related_codes ))
121+
64122
65123@admin .register (SourceInformation )
66124class SourceInformationAdmin (admin .ModelAdmin ):
0 commit comments