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!
Ok this was a bit stupid of me in the first place, but I found the answer and to anyone else that would like it, here it is!
Under INSTALLED_APPS:
I had installed my app as:
'bloxors'
but apparently in the documentation (after a decent amount of digging), You need to actually specify it as:
'bloxors.apps.BloxorsConfig'
The reason given was because, there is no default AppConfig set by django and it is upto the user to do so, which I wasn't aware of, so here you go!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With