from django.apps import AppConfig
from django.db.models.signals import pre_save


class {model_name}Config(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = '{model_name_name}'

    def ready(self):
        # Import the signal function here to ensure it's loaded when the app is ready
        from commons import signals
        from commons.utils.model_utils import CommonsModel
        from django.apps import apps

        # Iterate through all models registered with Django
        for model in apps.get_models():
            # Check if the model is a subclass of CommonsModel AND is not CommonsModel itself (since it's abstract)
            if issubclass(model, CommonsModel) and model is not CommonsModel:
                # Connect our signal receiver to the pre_save signal of this concrete model
                pre_save.connect(signals.set_user_fields_on_save, sender=model)