django 保存数据时重写?

需求:

class Article(Model.model):
    title = ''
    title_hash = hash(title)

实现方式1:

def save(self, *args, **kwargs):
    self.title_hash = hash(self.title)
    super(Article, self).save(*args, **kwargs)

实现方式2:

def save_title_hash(self):
    title_hash = hash(title)
    return title_hash
title_hash = property(save_title_hash)

原文链接:https://segmentfault.com/q/1010000003690416

文章作者:  BigYoung
版权声明:  本网站所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 BigYoung !