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

Default value is not applied back after clearing a preference #260

Closed hansegucker closed 2 years ago

hansegucker commented 2 years ago

When there is a preference called "test" with the default "123" and required=False, the initial value of the preference is of course "123". Then a user might change the preference and its value got "456". In the next step, the user clears the field and saves the preference. Now it's "", but I would expect it to get the default again ("123").

Natureshadow commented 2 years ago

I think the behaviour is correct. Well, "correct" is probably subjective, but it matches Django's behaviour for model fields (a model field with null=True and a default correctly behaves the same way).

agateblue commented 2 years ago

This is indeed the expected behaviour, and has several benefits. Accessing the preference from your code will set the value to the default, when needed. And if you need to apply the default value explicitely on a preference save, you can do it manually :)

agateblue commented 2 years ago

Also see https://github.com/agateblue/django-dynamic-preferences/issues/189 for more context/help