Closed ShirinovAdil closed 1 year ago
ImageField is TextField. So you can set image path as cli param.
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 errorCommandError: 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 ?
./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' `
I run
constance set HERO_IMAGE 'path/to/file/'
and get this errorCommandError: 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 formsCan 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'),
}
./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
Ok, that makes sense. All my questions are answered, thanks.
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.