Yesterday, I posted a new ticket asking about the potential for adding a 
standardised approach for packages to define default settings. [0]

I was writing an app, and when looking for a way to set settings, there was 
no clear solution.


Looking at what other projects do, the goto was something like this:
#myapp/settings.py
from django.conf import settings
MYAPP_SOME_SETTING = getattr(settings, 'MYAPP_SOME_SETTING', 'default')

This would then be accessed via myapp.settings, which will not reflect 
dynamic updates (specifically, override_settings).


What I feel is needed is this:
  - have apps access their settings via django.conf.settings, always
  - Allow to define default settings as cleanly as it is for settings to be 
written for projects.
  - Allow for dynamic settings that are calculated by default, but can be 
overridden by the project. [1]
  - *Nice to have: *This should ideally be written as a DEP so that it's 
usable on Django 1.11


*These are by no means final solutions. *I'm just looking to get the ball 
rolling.

I'd like to propose a couple of solutions for this to discuss.

- First, Load default_settings.py during the setup sequence.
I'm not sure how feasible this would be. What order would the settings app 
loads? what happens if your setting depends on another setting?

- Second, This could be done in AppConfig.
This introduces a fundamental new way of doing settings, and looks magical 
when using it.

class MyAppConfig(AppConfig):
    ...
    class DefaultSettings:
        MYAPP_SOME_SETTINGS = 'default'

        @property
        def MYAPP_DYNAMIC_SETTING(self):
            # set a default dynamically, based on environment or settings?

accessing settings.MYAPP_SOME_SETTINGS feels kind of strange though, as 
there's no direct relation between this new class and the 
django.conf.settings.

[0] https://code.djangoproject.com/ticket/27798
[1] 
https://github.com/YPlan/nexus/blob/620efbb7d13100848346c45717ca63d01ec301e5/nexus/conf.py

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/5498fb86-7fb9-4027-85ab-e3325b3c5ed5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to