def save(self, *args, **kwargs):
if self.secret:
self.hash_link = self.hash_secret()
else:
self.hash_link = None
super(News, self).save(*args, **kwargs)
def hash_secret(self):
encode_str = (self.slug[:3] + str(self.id) + self.content[:5]).encode(encoding='utf-8')
hash_lin = hashlib.md5(encode_str).hexdigest()
return mark_safe(u'<a href="/secret/{0}" target="_blank">{0}</a>'.format(hash_lin))