[Django]-Use signals in Django 1.9

4👍

From the release notes:

All models need to be defined inside an installed application or declare an explicit app_label. Furthermore, it isn’t possible to import them before their application is loaded. In particular, it isn’t possible to import models inside the root package of an application.

By importing your signals in __init__.py, you’re indirectly importing your models in the root package of your application. One option to avoid this is to change the sender to a string:

@receiver(pre_save, sender='<appname>.Comment')
def process_hashtags(sender, instance, **kwargs):
    ...

The recommended way to connect signals that use @receiver decorator in 1.9 is to create an application configuration, and import the signals module in AppConfig.ready().

👤knbk

Leave a comment