Django:保存时,如何检查字段是否已更改?
class Alias(MyBaseModel): remote_image = models.URLField(max_length=500, null=True, help_text="A URL that is downloaded and cached for the image. Only used when the alias is made") image = models.ImageField(upload_to='alias', default='alias-default.png', help_text="An image representing the alias") def save(self, *args, **kw): if (not self.image or self.image.name == 'alias-default.png') and self.remote_image : try : data = utils.fetch(self.remote_image) image = StringIO.StringIO(data) image = Image.open(image) buf = StringIO.StringIO() image.save(buf, format='PNG') self.image.save(hashlib.md5(self.string_id).hexdigest() + ".png", ContentFile(buf.getvalue())) except IOError : pass
remote_image
remote_image