作者:u44093631 | 来源:互联网 | 2024-12-20 16:18
导入models时,它就会报错,不管我改成self.slug或是Post.slug都是这样。提示说self或者Post not defined12345678910111213141516171819
导入models时,它就会报错,不管我改成self.slug或是Post.slug都是这样。提示说self或者Post not defined
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| class Post(models.Model):
title=models.CharField(max_length=70)
body=models.TextField()
created_time=models.DateTimeField()
modified_time=models.DateTimeField()
excerpt=models.CharField(max_length=200,blank=True)
category=models.ForeignKey(Category)
tags=models.ManyToManyField(Tag,blank=True)
author=models.ForeignKey(User)
views=models.PositiveIntegerField(default=0)
excerpt=models.CharField(max_length=100,blank=True)
sluglookup = models.SlugField(
unique=True,
default=Post.slug, ######这里这里这里报错!!!
max_length=15,
)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('blog:detail',kwargs={'pk':self.pk})
def increase_views(self):
self.views+=1
self.save(update_fields=['views'])
def save(self,*args,**kwargs):
if not self.excerpt:
md=markdown.Markdown(extensiOns=[
'markdown.extensions.extra',
'markdown.extensions.codehilite',
])
self.excerpt=strip_tags(md.convert(self.body))[:54]
super(Post,self).save(*args,**kwargs)
def slug(self):
return slugify(self.title) |