Using AppConfig to import signals is not working Django 2.08

I have an app companies. Inside the app there is a file called signals.py with the following code:

post_save.connect(update_descendants, sender=Company)

Inside companies apps.py I have:

class CompaniesConfig(AppConfig):
    name = 'apps.companies'

    def ready(self):
        from . import signals

But the signals are not imported/called.

If I import the file in models.py it work but it creates a circular import issue, and I need to this imports inside functions not at top.

Structure:

 - companies
   -apps
   -models
   -signals

Why app config is not working ?

If you are using a custom AppConfig class then you need to tell Django about it. It isn't automatically discovered. Reference in in the Django settings files like this:

INSTALLED_APPS [
    ....
    "companies.apps.CompaniesConfig",
    ....
]

Connecting Django Signals using the AppConfig ready handler , You may need to add an __init__.py file to the companies directory __init__.py can just be a blank file with that name. m2m_changed ¶ django.db.models.signals.m2m_changed¶ Sent when a ManyToManyField is changed on a model instance. Strictly speaking, this is not a model signal since it is sent by the ManyToManyField, but since it complements the pre_save / post_save and pre_delete / post_delete when it comes to tracking changes to models, it is included here.

You may need to add an __init__.py file to the companies directory...

__init__.py can just be a blank file with that name.

Django: automatically delete records - django - iOS, In the ready method, when I try to import signals , I get "No module named ' Signals'". Any thoughts on this? This was working with Django 1.10. My bad, I found the� Although you can’t import models at the module-level where AppConfig classes are defined, you can import them in ready(), using either an import statement or get_model(). If you’re registering model signals , you can refer to the sender by its string label instead of using the model class itself.

You need to add the appconfig in app's init.py:

default_app_config = 'apps.companies.CompaniesConfig'

This is along with the ready() in AppConfig which I see you already have in apps.py

Can I make a folder of forms and views and use an __init__.py file , Using AppConfig to import signals is not working Django 2.08. I have an app companies. Inside the app there is a file called signals.py with the following code: � There are two ways to send signals in Django. Signal.send(sender, **kwargs)¶ Signal.send_robust(sender, **kwargs)¶ To send a signal, call either Signal.send() (all built-in signals use this) or Signal.send_robust(). You must provide the sender argument (which is a class most of the time) and may provide as many other keyword arguments as you

Applications | Django documentation, Using AppConfig to import signals is not working Django 2.08. I have an app companies. Inside the app there is a file called signals.py with the following code: � In this post, we use the post_save signal to make our things done. To use signals in our django project, we can do it in two ways. For now I’m registering the signals inside our app config file

rebuild - #155620, If there is no default_app_config , Django uses the base AppConfig class. Example: from django.apps import AppConfig from django.db.models.signals import� This means the signals.py import statement must either be added to the end of the models.py file or in the app __init__.py file. The former avoids breaking test coverage, so may be preferable. Django 1.7+ does not require importing signals.py because that is handled by the AppConfig.ready() method. Import the signals.py file, like this:

Changelog.all ----------- Thu Jul 2 03:52:07 UTC 2020 , fixed skip-broken description (--ignore-broken -> --skip-broken) - removed versionlock.list installation. Migrate all configuration files below the /etc/pcp hierarchy. to fix problems with Python 2.6 (#475903) (currently causing broken deps with /usr/sbin/ns-slapd was killed by signal 11 (SIGSEGV) - typo in previous patch� DJANGO_SETTINGS_MODULE¶ When you use Django, you have to tell it which settings you’re using. Do this by using an environment variable, DJANGO_SETTINGS_MODULE. The value of DJANGO_SETTINGS_MODULE should be in Python path syntax, e.g. mysite.settings. Note that the settings module should be on the Python import search path.

Comments
  • I would say the name has to be without the apps part: name = 'companies'.
  • @guillermochamorro there are inside a folder called apps
  • it is a package so it has init_.py