2017-08-16 20:00:41 +00:00
|
|
|
from django.apps import AppConfig
|
2017-08-22 19:02:43 +00:00
|
|
|
from django.db.models import signals
|
|
|
|
|
|
|
|
|
|
|
|
def call_on_class_prepared(sender, **kwargs):
|
|
|
|
"""
|
|
|
|
Calls the function only if it is defined in the class being prepared
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
sender.on_class_prepared()
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
2017-08-16 20:00:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
class GamesConfig(AppConfig):
|
|
|
|
name = 'games'
|
2017-08-22 19:02:43 +00:00
|
|
|
|
|
|
|
def ready(self):
|
|
|
|
"""
|
|
|
|
Add signals to the application
|
|
|
|
"""
|
|
|
|
from .models import Game
|
|
|
|
from .signals import game_saved
|
|
|
|
signals.post_save.connect(game_saved, sender='games.Game')
|
|
|
|
|
|
|
|
def __init__(self, app_name, app_module):
|
|
|
|
super(GamesConfig, self).__init__(app_name, app_module)
|
|
|
|
signals.class_prepared.connect(call_on_class_prepared)
|