After Width: | Height: | Size: 683 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 52 KiB |
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 112 KiB |
After Width: | Height: | Size: 102 KiB |
After Width: | Height: | Size: 89 KiB |
After Width: | Height: | Size: 69 KiB |
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 44 KiB |
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 160 KiB |
After Width: | Height: | Size: 74 KiB |
After Width: | Height: | Size: 85 KiB |
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 92 KiB |
After Width: | Height: | Size: 6.4 KiB |
After Width: | Height: | Size: 66 KiB |
After Width: | Height: | Size: 1.5 MiB |
After Width: | Height: | Size: 769 KiB |
After Width: | Height: | Size: 754 KiB |
@ -0,0 +1,34 @@
|
|||||||
|
# Generated by Django 5.0.6 on 2024-05-28 16:55
|
||||||
|
|
||||||
|
import ckeditor_uploader.fields
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('post', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='category',
|
||||||
|
name='id',
|
||||||
|
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='post',
|
||||||
|
name='content',
|
||||||
|
field=ckeditor_uploader.fields.RichTextUploadingField(blank=True, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='post',
|
||||||
|
name='id',
|
||||||
|
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='tag',
|
||||||
|
name='id',
|
||||||
|
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
|
||||||
|
),
|
||||||
|
]
|
@ -0,0 +1,23 @@
|
|||||||
|
#coding=utf-8
|
||||||
|
from django.db.models import Count
|
||||||
|
|
||||||
|
from post.models import Post
|
||||||
|
|
||||||
|
|
||||||
|
def getRightInfo(request):
|
||||||
|
|
||||||
|
#1.获取分类信息
|
||||||
|
r_catepost = Post.objects.values('category__cname','category').annotate(c=Count('*')).order_by('-c')
|
||||||
|
|
||||||
|
#2.近期文章
|
||||||
|
r_recpost = Post.objects.all().order_by('-created')[:3]
|
||||||
|
|
||||||
|
#3.获取日期归档信息 原生查询
|
||||||
|
from django.db import connection
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute("select created,count('*') c from t_post GROUP BY DATE_FORMAT(created,'%Y-%m') ORDER BY c desc,created desc")
|
||||||
|
# 获取查询结果
|
||||||
|
r_filepost = cursor.fetchall()
|
||||||
|
|
||||||
|
# 返回获取的标签信息以字典的形式
|
||||||
|
return {'r_catepost':r_catepost,'r_recpost':r_recpost,'r_filepost':r_filepost}
|
@ -0,0 +1,35 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
帖子列表
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block left %}
|
||||||
|
|
||||||
|
|
||||||
|
<div id="main">
|
||||||
|
|
||||||
|
<div class="archives">
|
||||||
|
|
||||||
|
{% for post in postList %}
|
||||||
|
|
||||||
|
<article class="archive-article archive-type-post">
|
||||||
|
<div class="archive-article-inner">
|
||||||
|
<header class="archive-article-header">
|
||||||
|
<a href="#" class="archive-article-date">
|
||||||
|
<time>{{ post.created|date:'Y-m' }}</time>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<h1 itemprop="name">
|
||||||
|
<a class="archive-article-title" target="_blank" href="/post/{{ post.id }}">{{ post.title }}</a>
|
||||||
|
</h1>
|
||||||
|
</header>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
@ -0,0 +1,68 @@
|
|||||||
|
<aside id="sidebar">
|
||||||
|
<!--分类-->
|
||||||
|
<div class="widget-wrap">
|
||||||
|
<h3 class="widget-title">分类</h3>
|
||||||
|
<div class="widget">
|
||||||
|
<ul class="category-list">
|
||||||
|
|
||||||
|
{% for cp in r_catepost %}
|
||||||
|
<li class="category-list-item">
|
||||||
|
<a class="category-list-link" href="/category/{{ cp.category }}">{{ cp.category__cname }}</a>
|
||||||
|
<span class="category-list-count">{{ cp.c }}</span>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!--归档-->
|
||||||
|
<div class="widget-wrap">
|
||||||
|
<h3 class="widget-title">归档</h3>
|
||||||
|
<div class="widget">
|
||||||
|
<ul class="archive-list">
|
||||||
|
|
||||||
|
{% for fp in r_filepost %}
|
||||||
|
|
||||||
|
<li class="archive-list-item">
|
||||||
|
<a class="archive-list-link" href="/archive/{{ fp.0|date:'Y' }}/{{ fp.0|date:'m' }}">{{ fp.0|date:'Y年m月' }}</a>
|
||||||
|
<span class="archive-list-count">{{ fp.1 }}</span>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!--近期文章-->
|
||||||
|
<div class="widget-wrap">
|
||||||
|
<h3 class="widget-title">近期文章</h3>
|
||||||
|
<div class="widget">
|
||||||
|
<ul>
|
||||||
|
|
||||||
|
{% for rp in r_recpost %}
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<a href="/post/{{ rp.id }}" target="_blank">{{ rp.title|truncatechars:10 }}</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="widget-wrap">
|
||||||
|
<h3 class="widget-title">友情链接</h3>
|
||||||
|
<div class="widget">
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="http://www.bjsxt.com/" target="_blank">尚学堂</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="http://www.sxt.cn/" target="_blank">速学堂</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</aside>
|
@ -1,42 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import models
|
|
||||||
|
|
||||||
# Create your models here.
|
|
||||||
class Category(models.Model):
|
|
||||||
cname = models.CharField(max_length=30,unique=True,verbose_name=u'类别名称')
|
|
||||||
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
db_table = 't_category'
|
|
||||||
verbose_name_plural=u'类别'
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return u'Category:%s'%self.cname
|
|
||||||
|
|
||||||
class Tag(models.Model):
|
|
||||||
tname = models.CharField(max_length=30,unique=True,verbose_name=u'标签名称')
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
db_table = 't_tag'
|
|
||||||
verbose_name_plural = u'标签'
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return u'Tag:%s' % self.tname
|
|
||||||
|
|
||||||
class Post(models.Model):
|
|
||||||
title = models.CharField(max_length=100,unique=True)
|
|
||||||
desc = models.CharField(max_length=100)
|
|
||||||
content = models.TextField()
|
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
|
||||||
category = models.ForeignKey(Category,on_delete=models.CASCADE)
|
|
||||||
tag = models.ManyToManyField(Tag)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
db_table = 't_post'
|
|
||||||
verbose_name_plural = u'帖子'
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return u'Post:%s' % self.title
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
|||||||
#coding=utf-8
|
|
||||||
|
|
||||||
from django.conf.urls import url
|
|
||||||
import views
|
|
||||||
|
|
||||||
urlpatterns=[
|
|
||||||
url(r'^$',views.queryAll),
|
|
||||||
url(r'^page/(\d+)$',views.queryAll),
|
|
||||||
url(r'^post/(\d+)$',views.detail),
|
|
||||||
]
|
|
@ -1,109 +0,0 @@
|
|||||||
<aside id="sidebar">
|
|
||||||
<!--分类-->
|
|
||||||
<div class="widget-wrap">
|
|
||||||
<h3 class="widget-title">分类</h3>
|
|
||||||
<div class="widget">
|
|
||||||
<ul class="category-list">
|
|
||||||
|
|
||||||
|
|
||||||
<li class="category-list-item">
|
|
||||||
<a class="category-list-link" href="http://hello123.pythonanywhere.com/category/1">前端</a>
|
|
||||||
<span class="category-list-count">4</span>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="category-list-item">
|
|
||||||
<a class="category-list-link" href="http://hello123.pythonanywhere.com/category/2">后端</a>
|
|
||||||
<span class="category-list-count">3</span>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="category-list-item">
|
|
||||||
<a class="category-list-link" href="http://hello123.pythonanywhere.com/category/3">数据库</a>
|
|
||||||
<span class="category-list-count">1</span>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!--归档-->
|
|
||||||
<div class="widget-wrap">
|
|
||||||
<h3 class="widget-title">归档</h3>
|
|
||||||
<div class="widget">
|
|
||||||
<ul class="archive-list">
|
|
||||||
|
|
||||||
|
|
||||||
<li class="archive-list-item">
|
|
||||||
<a class="archive-list-link" href="http://hello123.pythonanywhere.com/archive/2018/06">2018年06月</a>
|
|
||||||
<span class="archive-list-count">6</span>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
|
|
||||||
<li class="archive-list-item">
|
|
||||||
<a class="archive-list-link" href="http://hello123.pythonanywhere.com/archive/2017/05">2017年05月</a>
|
|
||||||
<span class="archive-list-count">1</span>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
|
|
||||||
<li class="archive-list-item">
|
|
||||||
<a class="archive-list-link" href="http://hello123.pythonanywhere.com/archive/2017/06">2017年06月</a>
|
|
||||||
<span class="archive-list-count">1</span>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!--近期文章-->
|
|
||||||
<div class="widget-wrap">
|
|
||||||
<h3 class="widget-title">近期文章</h3>
|
|
||||||
<div class="widget">
|
|
||||||
<ul>
|
|
||||||
|
|
||||||
<li>
|
|
||||||
<a href="http://hello123.pythonanywhere.com/post/8" target="_blank">T4</a>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li>
|
|
||||||
<a href="http://hello123.pythonanywhere.com/post/7" target="_blank">T3</a>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li>
|
|
||||||
<a href="http://hello123.pythonanywhere.com/post/4" target="_blank">MySQL表连接</a>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="widget-wrap">
|
|
||||||
<h3 class="widget-title">友情链接</h3>
|
|
||||||
<div class="widget">
|
|
||||||
<ul>
|
|
||||||
<li>
|
|
||||||
<a href="http://www.bjsxt.com/" target="_blank">尚学堂</a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="http://www.sxt.cn/" target="_blank">速学堂</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</aside>
|
|