Skip to content

Commit 991f8c6

Browse files
committed
Fix country/pk/databank N+1 query issue
1 parent ff693fb commit 991f8c6

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

databank/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def __str__(self):
351351

352352
@property
353353
def appeals(self):
354-
return Appeal.objects.filter(country=self.country).all()
354+
return Appeal.objects.filter(country=self.country).select_related("dtype", "event")
355355

356356
@property
357357
def past_crises_events_count(self):

databank/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,4 @@ class Meta:
156156
fields = "__all__"
157157

158158
def get_founded_date(self, object):
159-
return Country.objects.filter(countryoverview=object).values_list("founded_date", flat=True).first()
159+
return getattr(object.country, "founded_date", None)

0 commit comments

Comments
 (0)