26👍
height_field
represents a property of your model which is used to store the height.
class Anh_chi_tiet(models.Model):
url_height=models.PositiveIntegerField()
url_width=models.PositiveIntegerField()
url = models.ImageField(upload_to='images', height_field='url_height', width_field='url_width')
Notice height_field='url_height'
14👍
I think you are misunderstanding what the height_field and width_field attributes are for.
The height_field isn’t used to change the height. It’s used to record what the height already is.
This way you can do something like
<img src="..." height={{my_instance.my_height_field}} />
without having to read the file.
If you are trying to resize all images uploaded via an ImageField, check here:
Image resizing with django?
- Django override the form HTML label template?
- Django Queryset of related objects, after prefiltering on original model
- Changes made to (static) CSS file not reflecting in Django development server
- Pycharm warns package requirement not satisfied when using pipenv to install package
Source:stackexchange.com