jazzband / django-constance

Dynamic Django settings.

Home Page:https://django-constance.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setting image_field value with CLI (Question)

ShirinovAdil opened this issue · comments

commented

HI!
I have a setting of an image_field type specified as in docs, is it somehow possible to set a value for it using the management command? I'm trying to make a new management command based on _set_constance_value but not sure what format should the image be and if it's possible at all.

  • Django version: 3.2
  • Python version: 3.8
  • Django-Constance version: latest

ImageField is TextField. So you can set image path as cli param.

commented

I run constance set HERO_IMAGE 'path/to/file/'
and get this error
CommandError: No file was submitted. Check the encoding type on the form.

My guess is it actually requires encoded image in some format since it works like Django forms

I run constance set HERO_IMAGE 'path/to/file/' and get this error CommandError: No file was submitted. Check the encoding type on the form.

My guess is it actually requires encoded image in some format since it works like Django forms

Can you attach your config for constance in a settings.py file ?

docs

./manage.py shell

`In [1]: from constance import config

In [2]: config.LOGO_IMAGE
Out[2]: 'Screenshot from 2023-02-08 22-17-31.png'

In [3]:

In [3]: setattr(config, 'LOGO_IMAGE', '/path/file.txt')

In [4]:

In [4]: config.LOGO_IMAGE
Out[4]: '/path/file.txt'
`

commented

I run constance set HERO_IMAGE 'path/to/file/' and get this error CommandError: No file was submitted. Check the encoding type on the form.
My guess is it actually requires encoded image in some format since it works like Django forms

Can you attach your config for constance in a settings.py file ?

CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend'
CONSTANCE_DBS = "default"
CONSTANCE_SUPERUSER_ONLY = False
CONSTANCE_ADDITIONAL_FIELDS = {
    'image_field': ['django.forms.ImageField', {'required': False}]
}
CONSTANCE_CONFIG = {
    'POWERED_BY_LOGO': ('', 'description', 'image_field'),
    'HERO_IMAGE': ('', 'description.', 'image_field'),
    'SIDEBAR_LOGO': ('', 'description', 'image_field'),
}
commented

docs

./manage.py shell

`In [1]: from constance import config

In [2]: config.LOGO_IMAGE Out[2]: 'Screenshot from 2023-02-08 22-17-31.png'

In [3]:

In [3]: setattr(config, 'LOGO_IMAGE', '/path/file.txt')

In [4]:

In [4]: config.LOGO_IMAGE Out[4]: '/path/file.txt' `

you're using setattr thus default constance set command is not suitable for that?

constance set works through django from which requires file to exist in memory

commented

Ok, that makes sense. All my questions are answered, thanks.