from django.conf import settings
from django.db.models.signals import post_save

from . import models


def autofollow_hook(instance, **kwargs):
    if hasattr(instance.project, 'id'):
        models.Follow.objects.get_or_create(
            project=instance.project,
            creator=instance.creator,
            defaults={
                'enabled': True,
            })


for model in settings.A4_AUTO_FOLLOWABLES:
    post_save.connect(autofollow_hook, model)

from django.apps import apps
from django.conf import settings
from django.db.models.signals import post_save

from . import models


def autofollow_hook(instance, **kwargs):
    if hasattr(instance.project, 'id'):
        models.Follow.objects.get_or_create(
            project=instance.project,
            creator=instance.creator,
            defaults={
                'enabled': True,
            })


for app, model in settings.A4_AUTO_FOLLOWABLES:
    post_save.connect(autofollow_hook, apps.get_model(app, model))

Fix setting up AUTO_FOLLOWABLES models
Fix setting up AUTO_FOLLOWABLES models

Note that `Signal.connect` expects the model class as the sender
argument.

Altough while using e.g. `post_save` it also works with a string
`"apname.model"`
