def get(self,request): if request.GET.get('type') == 'blog': all_blogs = Blog.objects.all() keywords = request.GET.get('keywords','') if keywords: all_results = all_blogs.filter(Q(title__icontains = keywords)|Q(content__icontains = keywords)|Q(want_to_say__icontains = keywords)).order_by('add_time') results = paging(all_results,request = request,nums = 4) return render(request,'search.html',{ 'name': 'blog', 'all_results': results, }) elif request.GET.get('type') == 'author': all_authors = UserProfile.objects.all() keywords = request.GET.get('keywords','') if keywords: all_results = all_authors.filter(Q(nick_name__icontains = keywords)|Q(desc__icontains = keywords)|Q(sign__icontains = keywords)) results = paging(all_results,request = request,nums = 4) return render(request,'search.html',{ 'name': 'author', 'all_results': results, })
def get(self,request,year,month): all_blogs = Blog.objects.filter(add_time__year = year,add_time__month = month).order_by('-add_time') blogs = paging(all_blogs,request = request) return render(request,'blog_archives.html',{ 'all_blogs':blogs, 'year':year, 'month':month, })
def get(self,request,category_id): category = Category.objects.get(id = category_id) all_blogs = category.blog_set.all() blogs = paging(all_blogs,request = request) return render(request,'blog_category.html',{ 'category':category, 'all_blogs':blogs, })
def get(self,request,tag_id): tag = Tag.objects.get(id = tag_id) all_blogs = tag.blog_set.all().order_by('-add_time') blogs = paging(all_blogs,request = request) return render(request,'blog_tag.html',{ 'all_blogs':blogs, 'tag':tag, })
def get(self,request): all_blogs = Blog.objects.all().order_by('-add_time') blogs = paging(all_blogs,request = request) #轮播博客 banner_blogs = Blog.objects.filter(is_banner = True).order_by('-add_time') return render(request,'index.html',{ 'all_blogs':blogs, 'banner_blogs':banner_blogs, })
def get(self, request): #取出关注作者记录 records = UserFav.objects.filter(user=request.user, fav_type=2) #取出作者id id_list = [each.fav_id for each in records] #取出关注作者 all_authors = UserProfile.objects.filter(id__in=id_list) authors = paging(all_authors, request=request, nums=5) return render(request, 'usercenter_fav_author.html', { 'all_authors': authors, })
def get(self, request): #取出关注博客记录 records = UserFav.objects.filter(user=request.user, fav_type=1) #取出博客id id_list = [each.fav_id for each in records] #取出关注作者 all_blogs = Blog.objects.filter(id__in=id_list) blogs = paging(all_blogs, request=request) return render(request, 'usercenter_fav_blog.html', { 'all_blogs': blogs, })
def get(self, request): all_blogs = Blog.objects.filter(author=request.user) sort = request.GET.get('sort', '') if sort == 'add_time': all_blogs = all_blogs.order_by('-add_time') elif sort == 'click': all_blogs = all_blogs.order_by('-click_nums') elif sort == 'fav': all_blogs = all_blogs.order_by('-fav_nums') blogs = paging(all_blogs, request=request) return render(request, 'usercenter_myblog.html', { 'all_blogs': blogs, })
def get(self,request,author_id): author = UserProfile.objects.get(id = author_id) author.click_nums += 1 author.save() all_blogs = author.blog_set.all() #是否收藏 has_fav = False if request.user.is_authenticated(): if UserFav.objects.filter(user = request.user,fav_id = author_id,fav_type = 2): has_fav = True blogs = paging(all_blogs,request = request,nums = 5) return render(request,'blog_author_detail.html',{ 'author':author, 'all_blogs':blogs, 'has_fav':has_fav, })