需求:
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