在Django的ImageField中使用height_field和width_field属性 [英] Using height_field and width_field attribute in ImageField of Django
本文介绍了在Django的ImageField中使用height_field和width_field属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个模型
class Anh_chi_tiet(models.Model):
du_an = models.ForeignKey(Du_an)
title = models.CharField(max_length=120)
url = models.ImageField(upload_to='images', height_field='50', width_field='100')
url_detail = models.ImageField(upload_to='images', height_field='200', width_field='400')
我总是会收到此错误:
'Anh_chi_tiet' object has no attribute '100'
似乎Django要求在同一张表Anh_chi_tiet中同时使用两个字段来保存height_field和width_field。
It seems Django require both the fields in the same table Anh_chi_tiet to save height_field and width_field.
如何直接设置这些值而无需在表中添加新字段?
How can I directly set these values without append new fields in my table?
推荐答案
height_field
代表模型的属性,用于存储高度。
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')
注意 height_field ='url_height'
这篇关于在Django的ImageField中使用height_field和width_field属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文