I can't seem to get my ready function under my AppConfig to work.
Here is my code from apps.py:
from django.apps import AppConfig
from django.contrib.auth.models import User
from django.db.models.signals import post_save, post_delete
from django.db.models import Max, Count
from .models import Player, PlayerStats, TotalLevels
class BloxorsConfig(AppConfig):
name = 'bloxors'
def ready(self):
MaxCurrentLevel = PlayerStats.objects.aggregate(max_levels=Max('level_no'))['max_levels']
PlayerCount = Player.objects.aggregate(count_players=Count('player_name', distinct=True))['count_players']
print(MaxCurrentLevel, PlayerCount)
I read in the documentation that ready() gets called each time at the beginning of manage.py runserver
but then why does nothing happen. Ideally I was expecting it to print the two values MaxCurrentLevel, PlayerCount
.
Can someone point out what I am doing wrong and help solve this?
As always, I greatly appreciate your answers!