首页 > django 保存数据时重写?

django 保存数据时重写?

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

保存title时自动生成title_hash


在model重写save 方法

大概是这样:

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


def save_title_hash(self):
    title_hash = hash(title)
    return title_hash
title_hash = property(save_title_hash)
【热门文章】
【热门文章】