agateblue / django-dynamic-preferences

Dynamic global and instance settings for your django project
https://django-dynamic-preferences.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
346 stars 86 forks source link

How to set a django setting dynamicly? #264

Closed nrbnlulu closed 2 years ago

nrbnlulu commented 2 years ago

I might be dumb but i went threw the docs and didnt find anything about this (except stating that its possible "settings change without server restart" ).

My goal is that the user will be able to change the smtp configuration of django mail backend to set his own smtp server..

Natureshadow commented 2 years ago

Hi,

I might be dumb but i went threw the docs and didnt find any thing about this. (I want my user to be able to change the smtp configuration of django mail backend..)

That's not how this tool works, it is completely independen of Django Settings.

Django Settings cannot be stored in the database, because at the time they are loaded, models and the database connection aren't ready yet.

That said, in AlekSIS, we have a nasty hack allowing to use preferences in Settings:

https://edugit.org/AlekSIS/official/AlekSIS-Core/-/blob/master/aleksis/core/util/core_helpers.py#L152

Lazy-wrapping the preferences retrieval can delay the evaluation until a request occurs, but only if the consumer of the setting doesn't use it at import time or such.

As you can see, the use case is entirely unsupported and you have been warned.

I am trying to come up with a better solution, but keep postponing it...

nrbnlulu commented 2 years ago

Hi, thanks. do you think your hack is reliable? i don't mind even making a restart to the server after the user changes this.

Natureshadow commented 2 years ago

Hi, thanks. do you think your hack is reliable?

No.

Natureshadow commented 1 year ago

Hi, thanks. do you think your hack is reliable

No.