Django apps - Using AppConfigs

When starting a new app, one of the requirements is to create an file with a class that inherits from the AppConfig class. Typically this has very minimal contents with just the name and label attributes set to a value. Additionally the default auto field might be set as well.

What you might not know is that you can have multiple AppConfig classes that could do different things. The template-partials library has a good example of this here. Carlton has setup two classes, one which does some auto configuration ("magic") and another without. I have been pondering this week as I write about apps what else having multiple classes could be used for, below are some ideas.

First up is having AppConfigs which let the user of a reusable app specify the primary key type they would like to use.

class AutoAppConfig(AppConfig):
    name = 'myapp'
    default_auto_field = 'django.db.models.AutoField'
    default = True

class UUIDAppConfig(AppConfig):
    name = 'myapp'
    default_auto_field = 'django.db.models.UUIDField'

Another typical use is to register signals in the ready method. Perhaps one use case could be to opt-in/out of these signals. This might be useful for a CI or Test environment or if there was a more explicit way of calling the relevant code. This could be expanded to load a different AppConfig per environment and therefore containing some settings or logic to within an app over adding settings to the main project settings or performing checks in this system on startup (although this might be better with the checks framework!)

Do you have any thoughts about what else the AppConfig class could be used for? or even having multiple classes?