Reading up on the topic, I see a lot of people create a constants.py
within each app dir. I place my constants within the class FooConfig(AppConfig)
for each config, e.g.
class FooConfig(AppConfig):
name = 'foo'
label = 'foo'
verbose_name = "Foo"
MY_CONSTANT_1 = 1
MY_CONSTANT_2 = 2
MY_CONSTANT_3 = 3
The reason I do this is one of the most common constants I want is the app name.
Then somewhere else in the app:
from .apps import FooConfig
link = reverse(f'{FooConfig.name}:index')
x = FooConfig.MY_CONSTANT_1 + 7
Is there a drawback? E.g. fragile startup import dependencies cycles? IS it bad practice? I have not come across others doing it this way.
I could put the app name and app label in constants.py
and then in apps.py
import the app name and app label:
from .constants import APP_NAME, APP_LABEL, APP_VERBOSE_NAME
class FooConfig(AppConfig):
name = APP_NAME
label = APP_LABEL
verbose_name = APP_VERBOSE_NAME