diff --git a/README.md b/README.md
index 6d97ef93..6f13d82b 100644
--- a/README.md
+++ b/README.md
@@ -44,8 +44,7 @@ windows电脑:
有详细的部署介绍.
为了安全起见,没有把`SECRET_KEY`上传到Github中而是在环境变量中配置的,如果你想要正常运行的话,需要修改`settings.py`中的`SECRET_KEY`为你自己的就可以了。
-如:
-`SECRET_KEY = 'n9ceqv38)#&mwuat@(mjb_p%em$e8$qyr#fw9ot!=ba6lijx-6'`
+如:`SECRET_KEY = 'n9ceqv38)#&mwuat@(mjb_p%em$e8$qyr#fw9ot!=ba6lijx-6'`
若本地部署后发现静态文件无法加载.请将`settings.py`中的`DEBUG=False`修改为`DEBUG=True`即可.
## 运行
@@ -65,17 +64,17 @@ windows电脑:
### 创建数据库
- 终端下执行:
+ 终端下执行:
./manage.py makemigrations
- ./manage.py migrate
+ ./manage.py migrate
### 创建超级用户
- 终端下执行:
+ 终端下执行:
./manage.py createsuperuser
### 创建测试数据
-终端下执行:
+终端下执行:
./manage.py create_testdata
### 收集静态文件
@@ -84,15 +83,26 @@ windows电脑:
./manage.py collectstatic --noinput
./manage.py compress --force
### 开始运行:
- 执行:
+ 执行:
`./manage.py runserver`
- 浏览器打开: http://127.0.0.1:8000/ 就可以看到效果了。
+ 浏览器打开: http://127.0.0.1:8000/ 就可以看到效果了。
## 问题相关
有任何问题欢迎提Issue,或者将问题描述发送至我邮箱 `liangliangyy#gmail.com`.我会尽快解答.推荐提交Issue方式.
+## 捐赠
+如果您觉得本项目对您有所帮助,欢迎您请我喝杯咖啡,您的支持是我最大的动力,您可以扫描下方二维码为我付款,谢谢。
+### 支付宝:
+
+
![](https://resource.lylinux.net/image/2017/12/16/IMG_0207.jpg)
+
+
+### 微信:
+
+
![](https://resource.lylinux.net/image/2017/12/16/IMG_0206.jpg)
+
diff --git a/accounts/models.py b/accounts/models.py
index e156199c..d396bd3b 100644
--- a/accounts/models.py
+++ b/accounts/models.py
@@ -2,6 +2,7 @@
from django.contrib.auth.models import AbstractUser, BaseUserManager
from django.core.urlresolvers import reverse
from django.contrib.sites.models import Site
+from django.utils.timezone import now
# Create your models here.
@@ -9,6 +10,8 @@
class BlogUser(AbstractUser):
nickname = models.CharField('昵称', max_length=50, blank=True)
mugshot = models.ImageField('头像', upload_to='upload/mugshots', blank=True)
+ created_time = models.DateTimeField('创建时间', default=now)
+ last_mod_time = models.DateTimeField('修改时间', default=now)
# objects = BlogUserManager()
diff --git a/blog/admin.py b/blog/admin.py
index ec6782d9..ea36708b 100644
--- a/blog/admin.py
+++ b/blog/admin.py
@@ -39,7 +39,7 @@ class ArticlelAdmin(admin.ModelAdmin):
list_display_links = ('id', 'title')
list_filter = (ArticleListFilter, 'status', 'type', 'category', 'tags')
filter_horizontal = ('tags',)
- exclude = ('slug', 'created_time')
+ exclude = ('slug', 'created_time', 'last_mod_time')
def get_form(self, request, obj=None, **kwargs):
form = super(ArticlelAdmin, self).get_form(request, obj, **kwargs)
@@ -53,15 +53,19 @@ def save_model(self, request, obj, form, change):
class TagAdmin(admin.ModelAdmin):
- exclude = ('slug',)
+ exclude = ('slug', 'last_mod_time', 'created_time')
class CategoryAdmin(admin.ModelAdmin):
- exclude = ('slug',)
+ exclude = ('slug', 'last_mod_time', 'created_time')
+
+
+class LinksAdmin(admin.ModelAdmin):
+ exclude = ('last_mod_time', 'created_time')
admin.site.register(Article, ArticlelAdmin)
# admin.site.register(BlogPage, ArticlelAdmin)
admin.site.register(Category, CategoryAdmin)
admin.site.register(Tag, TagAdmin)
-admin.site.register(Links)
+admin.site.register(Links, LinksAdmin)
diff --git a/blog/management/commands/create_testdata.py b/blog/management/commands/create_testdata.py
index e9f4adeb..7479040b 100644
--- a/blog/management/commands/create_testdata.py
+++ b/blog/management/commands/create_testdata.py
@@ -25,25 +25,28 @@ class Command(BaseCommand):
def handle(self, *args, **options):
user = \
- get_user_model().objects.get_or_create(email='test@test.com', username='testuser',
+ get_user_model().objects.get_or_create(email='test@test.com', username='测试用户',
password='test!q@w#eTYU')[0]
- pcategory = Category.objects.get_or_create(name='pcategory', parent_category=None)[0]
+ pcategory = Category.objects.get_or_create(name='我是父类目', parent_category=None)[0]
- category = Category.objects.get_or_create(name='category', parent_category=pcategory)[0]
+ category = Category.objects.get_or_create(name='子类目', parent_category=pcategory)[0]
category.save()
-
- for i in range(1, 10):
+ basetag = Tag()
+ basetag.name = "标签"
+ basetag.save()
+ for i in range(1, 20):
article = Article.objects.get_or_create(category=category,
title='nice title ' + str(i),
body='nice content ' + str(i),
author=user
)[0]
tag = Tag()
- tag.name = "nicetag" + str(i)
+ tag.name = "标签" + str(i)
tag.save()
article.tags.add(tag)
+ article.tags.add(basetag)
article.save()
from DjangoBlog.utils import cache
diff --git a/blog/models.py b/blog/models.py
index 22f8436d..ea598495 100644
--- a/blog/models.py
+++ b/blog/models.py
@@ -6,10 +6,13 @@
from django.contrib.sites.models import Site
from DjangoBlog.utils import cache_decorator, logger, cache
from django.utils.functional import cached_property
+from django.utils.timezone import now
class BaseModel(models.Model):
slug = models.SlugField(default='no-slug', max_length=60, blank=True)
+ created_time = models.DateTimeField('创建时间', default=now)
+ last_mod_time = models.DateTimeField('修改时间', default=now)
def save(self, *args, **kwargs):
from DjangoBlog.blog_signals import article_save_signal
@@ -19,7 +22,7 @@ def save(self, *args, **kwargs):
super().save(*args, **kwargs)
# type = self.__class__.__name__
is_update_views = 'update_fields' in kwargs and len(kwargs['update_fields']) == 1 and kwargs['update_fields'][
- 0] == 'views'
+ 0] == 'views'
article_save_signal.send(sender=self.__class__, is_update_views=is_update_views, id=self.id)
def get_full_url(self):
@@ -47,8 +50,6 @@ class Article(BaseModel):
)
title = models.CharField('标题', max_length=200, unique=True)
body = models.TextField('正文')
- created_time = models.DateTimeField('创建时间', auto_now_add=True)
- last_mod_time = models.DateTimeField('修改时间', auto_now=True)
pub_time = models.DateTimeField('发布时间', blank=True, null=True)
status = models.CharField('文章状态', max_length=1, choices=STATUS_CHOICES, default='p')
comment_status = models.CharField('评论状态', max_length=1, choices=COMMENT_STATUS, default='o')
@@ -124,8 +125,6 @@ def prev_article(self):
class Category(BaseModel):
"""文章分类"""
name = models.CharField('分类名', max_length=30, unique=True)
- created_time = models.DateTimeField('创建时间', auto_now_add=True)
- last_mod_time = models.DateTimeField('修改时间', auto_now=True)
parent_category = models.ForeignKey('self', verbose_name="父级分类", blank=True, null=True)
class Meta:
@@ -180,8 +179,6 @@ def parse(category):
class Tag(BaseModel):
"""文章标签"""
name = models.CharField('标签名', max_length=30, unique=True)
- created_time = models.DateTimeField('创建时间', auto_now_add=True)
- last_mod_time = models.DateTimeField('修改时间', auto_now=True)
def __str__(self):
return self.name
@@ -204,8 +201,8 @@ class Links(models.Model):
name = models.CharField('链接名称', max_length=30, unique=True)
link = models.URLField('链接地址')
sequence = models.IntegerField('排序', unique=True)
- created_time = models.DateTimeField('创建时间', auto_now_add=True)
- last_mod_time = models.DateTimeField('修改时间', auto_now=True)
+ created_time = models.DateTimeField('创建时间', default=now)
+ last_mod_time = models.DateTimeField('修改时间', default=now)
class Meta:
ordering = ['sequence']
diff --git a/blog/templatetags/blog_tags.py b/blog/templatetags/blog_tags.py
index 878a655a..46cd1a8f 100644
--- a/blog/templatetags/blog_tags.py
+++ b/blog/templatetags/blog_tags.py
@@ -21,6 +21,7 @@
from django.core.urlresolvers import reverse
from blog.models import Article, Category, Tag, Links
from django.utils.encoding import force_text
+from django.shortcuts import get_object_or_404
import hashlib
import urllib
from comments.models import Comment
@@ -178,12 +179,13 @@ def load_pagination_info(page_obj, page_type, tag_name):
previous_number = page_obj.previous_page_number()
previous_url = reverse('blog:index_page', kwargs={'page': previous_number})
if page_type == '分类标签归档':
+ tag = get_object_or_404(Tag, name=tag_name)
if page_obj.has_next():
next_number = page_obj.next_page_number()
- next_url = reverse('blog:tag_detail_page', kwargs={'page': next_number, 'tag_name': tag_name})
+ next_url = reverse('blog:tag_detail_page', kwargs={'page': next_number, 'tag_name': tag.slug})
if page_obj.has_previous():
previous_number = page_obj.previous_page_number()
- previous_url = reverse('blog:tag_detail_page', kwargs={'page': previous_number, 'tag_name': tag_name})
+ previous_url = reverse('blog:tag_detail_page', kwargs={'page': previous_number, 'tag_name': tag.slug})
if page_type == '作者文章归档':
if page_obj.has_next():
next_number = page_obj.next_page_number()
@@ -193,13 +195,15 @@ def load_pagination_info(page_obj, page_type, tag_name):
previous_url = reverse('blog:author_detail_page', kwargs={'page': previous_number, 'author_name': tag_name})
if page_type == '分类目录归档':
+ category = get_object_or_404(Category, name=tag_name)
if page_obj.has_next():
next_number = page_obj.next_page_number()
- next_url = reverse('blog:category_detail_page', kwargs={'page': next_number, 'category_name': tag_name})
+ next_url = reverse('blog:category_detail_page',
+ kwargs={'page': next_number, 'category_name': category.slug})
if page_obj.has_previous():
previous_number = page_obj.previous_page_number()
previous_url = reverse('blog:category_detail_page',
- kwargs={'page': previous_number, 'category_name': tag_name})
+ kwargs={'page': previous_number, 'category_name': category.slug})
return {
'previous_url': previous_url,
diff --git a/blog/tests.py b/blog/tests.py
index 5df565eb..48f336b9 100644
--- a/blog/tests.py
+++ b/blog/tests.py
@@ -73,15 +73,15 @@ def test_validate_article(self):
self.assertIsNotNone(s)
p = Paginator(Tag.objects.all(), 2)
- s = load_pagination_info(p.page(1), '分类标签归档', 'tagname')
+ s = load_pagination_info(p.page(1), '分类标签归档', tag.slug)
self.assertIsNotNone(s)
p = Paginator(BlogUser.objects.all(), 2)
- s = load_pagination_info(p.page(1), '作者文章归档', 'username')
+ s = load_pagination_info(p.page(1), '作者文章归档', 'liangliangyy')
self.assertIsNotNone(s)
p = Paginator(Category.objects.all(), 2)
- s = load_pagination_info(p.page(1), '分类目录归档', 'categoryname')
+ s = load_pagination_info(p.page(1), '分类目录归档', category.slug)
self.assertIsNotNone(s)
f = BlogSearchForm()
diff --git a/blog/urls.py b/blog/urls.py
index 67878111..870e2937 100644
--- a/blog/urls.py
+++ b/blog/urls.py
@@ -42,8 +42,8 @@
url(r'^author/(?P\w+)/(?P\d+).html$', views.AuthorDetailView.as_view(),
name='author_detail_page'),
- url(r'^tag/(?P.+).html$', views.TagDetailView.as_view(), name='tag_detail'),
- url(r'^tag/(?P.+)/(?P\d+).html$', views.TagDetailView.as_view(), name='tag_detail_page'),
+ url(r'^tag/(?P[\w-]+).html$', views.TagDetailView.as_view(), name='tag_detail'),
+ url(r'^tag/(?P[\w-]+)/(?P\d+).html$', views.TagDetailView.as_view(), name='tag_detail_page'),
url(r'^upload', views.fileupload, name='upload'),
url(r'^refresh', views.refresh_memcache, name='refresh')
diff --git a/comments/models.py b/comments/models.py
index b13b780b..708a0996 100644
--- a/comments/models.py
+++ b/comments/models.py
@@ -2,14 +2,15 @@
from django.conf import settings
from blog.models import Article
from DjangoBlog.utils import logger
+from django.utils.timezone import now
# Create your models here.
class Comment(models.Model):
body = models.TextField('正文', max_length=300)
- created_time = models.DateTimeField('创建时间', auto_now_add=True)
- last_mod_time = models.DateTimeField('修改时间', auto_now=True)
+ created_time = models.DateTimeField('创建时间', default=now)
+ last_mod_time = models.DateTimeField('修改时间', default=now)
author = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name='作者', on_delete=models.CASCADE)
article = models.ForeignKey(Article, verbose_name='文章', on_delete=models.CASCADE)
parent_comment = models.ForeignKey('self', verbose_name="上级评论", blank=True, null=True)
diff --git a/oauth/models.py b/oauth/models.py
index 6725bb37..76900c88 100644
--- a/oauth/models.py
+++ b/oauth/models.py
@@ -2,6 +2,7 @@
# Create your models here.
from django.conf import settings
+from django.utils.timezone import now
class OAuthUser(models.Model):
@@ -13,6 +14,8 @@ class OAuthUser(models.Model):
type = models.CharField(blank=False, null=False, max_length=50)
email = models.CharField(max_length=50, null=True, blank=True)
matedata = models.CharField(max_length=2000, null=True, blank=True)
+ created_time = models.DateTimeField('创建时间', default=now)
+ last_mod_time = models.DateTimeField('修改时间', default=now)
def __str__(self):
return self.nikename
diff --git a/templates/share_layout/footer.html b/templates/share_layout/footer.html
index 4196155f..b64dc0d8 100644
--- a/templates/share_layout/footer.html
+++ b/templates/share_layout/footer.html
@@ -21,7 +21,9 @@
Powered by
Django
|
- LiangLiangyy
+ LiangLiangyy
+ |
+ Lylinux
|
本页面加载耗时:s