updated = models.DateTimeField(auto_now=True, verbose_name='博客更新时间')
# 博客
class blog(models.Model):
list = models.ForeignKey(blogList, on_delete=models.CASCADE, verbose_name='博客系列标题')
title = models.CharField(max_length=20, verbose_name='博客名')
author = models.CharField(max_length=20, verbose_name='博客作者')
summary = models.TextField(max_length=300, verbose_name='博客简介')
content = RichTextUploadingField(verbose_name='博客内容')
image = models.ImageField(upload_to='blogList/%Y%m%d/', blank=True, verbose_name='博客配图')
created = models.DateTimeField(default=timezone.now, verbose_name='博客创建时间')
updated = models.DateTimeField(auto_now=True, verbose_name='博客更新时间')
index = models.PositiveIntegerField(default=0, verbose_name='博客排序')
tag = models.PositiveIntegerField(default=0, verbose_name='博客标签')
views = models.PositiveIntegerField(default=0, verbose_name='博客总浏览')
likes = models.PositiveIntegerField(default=0, verbose_name='博客总赞数')
comments = models.PositiveIntegerField(default=0, verbose_name='博客总评论')
class Meta:
verbose_name_plural = U'博客'
def __str__(self):
return U'blog:%s' % self.title
def blogdetail_view(request, id):
blogDetail = blog.objects.get(id=id)
# 更新浏览数
blogDetail.views += 1
blogDetail.save()
return render(request, 'blog/blogDetail.html', locals())
blogDetailViews = blogDetail.views + 1
blog.objects.filter(id=id).update(views=blogDetailViews)
return render(request, 'blog/blogDetail.html', locals())
from django.db.models import F
blog.objects.filter(id=id).update(views=F('views')+1)
from django.db.models import F
def blogdetail_view(request, id):
blogDetail = blog.objects.get(id=id)
# 更新浏览数
# blogDetailViews = blogDetail.views + 1
# blog.objects.filter(id=id).update(views=blogDetailViews)
blog.objects.filter(id=id).update(views=F('views')+1)
return render(request, 'blog/blogDetail.html', locals())
blogDetail = blog.objects.get(id=id)
blogDetail.views += 1
blogDetail.save()
blogDetailViews = blogDetail.views + 1
blog.objects.filter(id=id).update(views=blogDetailViews)
<span>{{ blogDetail.views }}</span>
<span>{{ blogDetailViews }}</span>
from django.db.models import F
def blogdetail_view(request, id):
# 更新浏览数
blog.objects.filter(id=id).update(views=F('views')+1)
blogDetail = blog.objects.get(id=id)
return render(request, 'blog/blogDetail.html', locals())
from django.db.models import F
def blogdetail_view(request, id):
blogDetail = blog.objects.get(id=id)
# 更新浏览数
blog.objects.filter(id=id).update(views=F('views')+1)
# 重新获取最新的数据
blogDetail.refresh_from_db()
return render(request, 'blog/blogDetail.html', locals())
此页面不支持夜间模式!
已进入夜间模式!
已进入普通模式!
搜索框不允许为空
签到成功!经验+5!芋圆币+2!
签到失败!今日已签到!
需要登录社区账号才可以进入!