Skip to content

Commit

Permalink
cache the average property, allowlist crsf token
Browse files Browse the repository at this point in the history
  • Loading branch information
ddunne6 committed May 13, 2023
1 parent 75f6170 commit 59be022
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app_ratings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.contrib.auth.models import User
from django.db.models import Avg
from django_countries.fields import CountryField
from django.utils.functional import cached_property

class Country(models.Model):
running_order = models.IntegerField()
Expand All @@ -17,8 +18,7 @@ class Meta:
def __str__(self):
return self.country.name

# average
@property
@cached_property
def average_score(self):
avg = Rating.objects.filter(country=self.id).aggregate(Avg('score'))
avg = avg['score__avg']
Expand Down
1 change: 1 addition & 0 deletions django_euro_vote/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
DEVELOPMENT_MODE = env('DEVELOPMENT', default=False)

ALLOWED_HOSTS = ['localhost', 'eurovote.azurewebsites.net']
CSRF_TRUSTED_ORIGINS = ['https://eurovote.azurewebsites.net']


# Application definition
Expand Down

0 comments on commit 59be022

Please sign in to comment.