更新1.2.3,详情见readme文件
This commit is contained in:
parent
ef7bb46317
commit
b07073f0cc
@ -56,4 +56,11 @@ python manage.py runserver 9999
|
||||
2025年6月23日
|
||||
新增
|
||||
1.友联管理
|
||||
2.站点设置
|
||||
2.站点设置
|
||||
|
||||
###### 1.2.3
|
||||
2025年6月234日
|
||||
新增
|
||||
1.分类管理
|
||||
2.文章分类的设置
|
||||
3.分类文章的列表
|
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -22,4 +22,8 @@ class ArticlesLikeAdmin(admin.ModelAdmin):
|
||||
# 分页显示,一页的数量
|
||||
list_per_page = 10
|
||||
|
||||
actions_on_top = True
|
||||
actions_on_top = True
|
||||
|
||||
@admin.register(ArticleTag)
|
||||
class ArticleTagAdmin(admin.ModelAdmin):
|
||||
list_display = ('id', 'tag')
|
31
home/migrations/0007_articletag_articles_tag_id.py
Normal file
31
home/migrations/0007_articletag_articles_tag_id.py
Normal file
@ -0,0 +1,31 @@
|
||||
# Generated by Django 4.2.23 on 2025-06-24 01:37
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('home', '0006_alter_articles_table_alter_articleslike_table'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ArticleTag',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('tag', models.CharField(max_length=120)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': '标签',
|
||||
'verbose_name_plural': '标签管理',
|
||||
'db_table': 'ArticleTag',
|
||||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='articles',
|
||||
name='tag_id',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='home.articletag', verbose_name='文章标签'),
|
||||
),
|
||||
]
|
Binary file not shown.
@ -2,15 +2,25 @@ from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
class ArticleTag(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
tag = models.CharField(max_length=120)
|
||||
def __str__(self):
|
||||
return self.tag
|
||||
class Meta:
|
||||
verbose_name = "标签"
|
||||
verbose_name_plural = "标签管理"
|
||||
db_table = 'ArticleTag'
|
||||
|
||||
class Articles(models.Model):
|
||||
title = models.CharField(max_length=100,verbose_name="文章标题")
|
||||
content = models.TextField(verbose_name="文章内容")
|
||||
abstract = models.TextField(verbose_name="文章摘要")
|
||||
author = models.TextField(default="admin", verbose_name="文章作者")
|
||||
# created = models.DateTimeField(auto_now_add=True,verbose_name="发布时间")
|
||||
created = models.DateTimeField(verbose_name="发布时间")
|
||||
stat = models.IntegerField(default=0,verbose_name="点赞数量")
|
||||
read = models.IntegerField(default=0,verbose_name="阅读数量")
|
||||
tag_id = models.ForeignKey(ArticleTag, on_delete=models.SET_NULL, null=True, blank=True, verbose_name="文章标签")
|
||||
|
||||
|
||||
class Meta:
|
||||
|
@ -19,11 +19,9 @@
|
||||
<div class="logo"><a href="/">{{ site_config.title }}</a></div>
|
||||
|
||||
<nav class="nav-links">
|
||||
<a href="#">前端技术</a>
|
||||
<a href="#">后端开发</a>
|
||||
<a href="#">生活随笔</a>
|
||||
<a href="#">关于我</a>
|
||||
<a href="#">关于我</a>
|
||||
{% for tag in tags %}
|
||||
<a href="/category/{{ tag.id }}">{{ tag.name }}</a>
|
||||
{% endfor %}
|
||||
</nav>
|
||||
|
||||
<div class="search-box">
|
||||
@ -56,11 +54,9 @@
|
||||
<div class="footer-section">
|
||||
<h3>分类</h3>
|
||||
<div class="footer-links">
|
||||
<a href="#">前端技术</a>
|
||||
<a href="#">后端开发</a>
|
||||
<a href="#">数据库</a>
|
||||
<a href="#">生活随笔</a>
|
||||
<a href="#">读书笔记</a>
|
||||
{% for tag in tags %}
|
||||
<a href="/category/{{ tag.id }}">{{ tag.name }}</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -4,5 +4,6 @@ from home import views as v
|
||||
|
||||
urlpatterns = [
|
||||
path('',v.index),
|
||||
path('archives/<id>', v.archives)
|
||||
path('archives/<id>', v.archives),
|
||||
path('category/<id>', v.category)
|
||||
]
|
@ -1,9 +1,11 @@
|
||||
from django.shortcuts import render, HttpResponse
|
||||
from pip._vendor.rich.markup import Tag
|
||||
|
||||
from home.models import *
|
||||
from comment.models import *
|
||||
from siteconfig.models import *
|
||||
# Create your views here.
|
||||
|
||||
# 获取站点信息的函数
|
||||
def get_site_config():
|
||||
siteconf = SiteConfig.objects.all()[0]
|
||||
siteconfig = {
|
||||
@ -14,47 +16,30 @@ def get_site_config():
|
||||
"icp": siteconf.icp,
|
||||
}
|
||||
return siteconfig
|
||||
|
||||
# 获取标签列表的函数
|
||||
def get_tag_list():
|
||||
taginfos = ArticleTag.objects.all()
|
||||
tags = []
|
||||
for taginfo in taginfos:
|
||||
tags.append({"name":taginfo.tag,"id":taginfo.id})
|
||||
return tags
|
||||
# 获取友情链接列表的函数
|
||||
def get_friendship_links():
|
||||
friendship_links = []
|
||||
FriendshipLinks = FriendshipLink.objects.all()
|
||||
for link in FriendshipLinks:
|
||||
friendship_links.append({"link": link.friendship_site_link,"name": link.friendship_site_name})
|
||||
return friendship_links
|
||||
def index(request):
|
||||
artchle = Articles.objects.all()
|
||||
|
||||
artchles = {
|
||||
"artchles": [],
|
||||
"site_config": get_site_config(),
|
||||
"FriendshipLinks": get_friendship_links()
|
||||
}
|
||||
for i in artchle:
|
||||
a = {
|
||||
"id":i.id,
|
||||
"title": i.title,
|
||||
"abstract": i.abstract,
|
||||
"created": i.created,
|
||||
"stat": i.stat,
|
||||
"read": i.read,
|
||||
}
|
||||
artchles["artchles"].append(a)
|
||||
|
||||
return render(request, 'index.html', context=artchles)
|
||||
|
||||
|
||||
def archives(request, id):
|
||||
# 获取文章详情的函数
|
||||
def get_archives_info(id):
|
||||
i = Articles.objects.get(id=id)
|
||||
i.read += 1
|
||||
i.save()
|
||||
previous_article = Articles.objects.filter(id__lt=id).order_by('-id').first()
|
||||
previous_id = previous_article.id if previous_article else id
|
||||
previous_id_title = previous_article.title if previous_article else "暂无上一篇"
|
||||
next_article = Articles.objects.filter(id__gt=id).order_by('id').first()
|
||||
next_id = next_article.id if next_article else id
|
||||
next_id_title = next_article.title if next_article else "暂无下一篇"
|
||||
comments = Comment.objects.filter(archives_id=id).order_by("-comment_time").all()
|
||||
a = {
|
||||
return {
|
||||
"id": i.id,
|
||||
"title": i.title,
|
||||
"abstract": i.abstract,
|
||||
@ -71,9 +56,44 @@ def archives(request, id):
|
||||
"id": next_id,
|
||||
"title": next_id_title,
|
||||
},"comments": [],
|
||||
"FriendshipLinks": get_friendship_links()
|
||||
"FriendshipLinks": get_friendship_links(),
|
||||
"tags": get_tag_list()
|
||||
}
|
||||
print(a)
|
||||
# 获取文章列表的函数(option不为1时以tag_id进行查询)
|
||||
def get_artchle(option=1,id=None):
|
||||
if option == 1:
|
||||
artchle = Articles.objects.all()
|
||||
else:
|
||||
artchle = Articles.objects.filter(tag_id=id).all()
|
||||
|
||||
artchles = {
|
||||
"artchles": [],
|
||||
"site_config": get_site_config(),
|
||||
"FriendshipLinks": get_friendship_links(),
|
||||
"tags": get_tag_list()
|
||||
}
|
||||
for i in artchle:
|
||||
a = {
|
||||
"id": i.id,
|
||||
"title": i.title,
|
||||
"abstract": i.abstract,
|
||||
"created": i.created,
|
||||
"stat": i.stat,
|
||||
"read": i.read,
|
||||
}
|
||||
artchles["artchles"].append(a)
|
||||
return artchles
|
||||
# 首页视图函数
|
||||
def index(request):
|
||||
return render(request, 'index.html', context=get_artchle())
|
||||
# 文章页视图函数
|
||||
def archives(request, id):
|
||||
i = Articles.objects.get(id=id)
|
||||
i.read += 1
|
||||
i.save()
|
||||
|
||||
comments = Comment.objects.filter(archives_id=id).order_by("-comment_time").all()
|
||||
a = get_archives_info(id)
|
||||
for c in comments:
|
||||
com = {
|
||||
"id": c.id,
|
||||
@ -83,4 +103,7 @@ def archives(request, id):
|
||||
"qq": c.qq,
|
||||
}
|
||||
a["comments"].append(com)
|
||||
return render(request, 'archives.html', a)
|
||||
return render(request, 'archives.html', a)
|
||||
# 分类页视图函数
|
||||
def category(request,id):
|
||||
return render(request, 'index.html', context=get_artchle(option=2,id=id))
|
Loading…
x
Reference in New Issue
Block a user