Using height_field and width_field attribute in ImageField of Django

前端 未结 2 786
栀梦
栀梦 2021-02-05 16:04

I have a model

class Anh_chi_tiet(models.Model):
    du_an       = models.ForeignKey(Du_an)
    title       = models.CharField(max_length=120)
    url         =         


        
2条回答
  •  囚心锁ツ
    2021-02-05 16:34

    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'

提交回复
热议问题