fabiocaccamo / django-extra-settings

:gear: config and manage typed extra settings using just the django admin.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Please clarify how to use EXTRA_SETTINGS_DEFAULTS

swasher opened this issue · comments

commented

django==4.2
django-extra-settings==0.9.1
Python 3.11.2

I'm use this extension and it work fine.

Howerer, I can't understand how to use default settings via settings.py. Steps what i do:

  1. drop db, then makemigraions and migrate (at this point all work fine, and extra_settings_setting db is empty)
  2. Add section so settings.py:
EXTRA_SETTINGS_DEFAULTS = [
    {
        "name": "margin_top",
        "type": 'int',
        "value": "7",
    },
]

3; Start server by manage.py server and got following error:

> python.exe C:\Users\OLEKSII\GitHub\printMES\manage.py runserver 127.0.0.1:8000 
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Users\OLEKSII\.virtualenvs\printMES-wR4SQlij\Lib\site-packages\django\db\models\query.py", line 916, in get_or_create
    return self.get(**kwargs), False
           ^^^^^^^^^^^^^^^^^^
  File "C:\Users\OLEKSII\.virtualenvs\printMES-wR4SQlij\Lib\site-packages\django\db\models\query.py", line 637, in get
    raise self.model.DoesNotExist(
extra_settings.models.Setting.DoesNotExist: Setting matching query does not exist.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\OLEKSII\.virtualenvs\printMES-wR4SQlij\Lib\site-packages\django\db\backends\utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "extra_settings_setting_name_key"
DETAIL:  Key (name)=(MARGIN_TOP) already exists.

Checking extra_settings_setting db i see a MARGIN_TOP record.

Can you add more clear documentatoin how to use EXTRA_SETTINGS_DEFAULTS?
Do I understand correctly that I can use EXTRA_SETTINGS_DEFAULTS for maintaining default values set with the source code?

Fund with Polar

@swasher sorry for the late answer.

EXTRA_SETTINGS_DEFAULTS should be automatically created in the database on app ready if they don't exist yet.

https://github.com/fabiocaccamo/django-extra-settings/blob/main/extra_settings/models.py#L99

I fixed a problem that could interfere with EXTRA_SETTINGS_DEFAULTS setting, could you please upgrade to the latest version (0.10.0) and tell me if it works as expected or not?

commented

Thank you, now work like a charm!