改写model的save()方法
作者:
叶田的学习笔记 | 来源:发表于
2018-10-24 21:04 被阅读0次from django.db import models
from django.utils.html import strip_tags
class Blog(models.Model):
title = models.CharField(max_length=70,blank=True, default='')
code = models.TextField()
created = models.DateTimeField(auto_now_add=True)
excerpt = models.CharField(max_length=200,blank=True) # 摘要
def __str__(self):
return self.title
def save(self, *args, **kwargs):
if not self.excerpt:
self.excerpt = strip_tags(self.body)[:50]
super().save(*args, **kwargs)
本文标题:改写model的save()方法
本文链接:https://www.haomeiwen.com/subject/fvfftqtx.html
网友评论