Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加文章排序 #119

Merged
merged 1 commit into from
May 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions DjangoBlog/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ class DjangoBlogFeed(Feed):
feed_type = Rss201rev2Feed

description = '大巧无工,重剑无锋.'
feed_url = 'https://www.lylinux.net/feed'
title = "且听风吟 大巧无工,重剑无锋. "
link = "https://www.lylinux.net"
link = "/feed/"

def author_name(self):
return get_user_model().objects.first().nickname
Expand Down
2 changes: 1 addition & 1 deletion blog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def open_article_commentstatus(modeladmin, request, queryset):
class ArticlelAdmin(admin.ModelAdmin):
search_fields = ('body',)
form = ArticleForm
list_display = ('id', 'title', 'author', 'created_time', 'views', 'status', 'type')
list_display = ('id', 'title', 'author', 'created_time', 'views', 'status', 'type','article_order')
list_display_links = ('id', 'title')
list_filter = (ArticleListFilter, 'status', 'type', 'category', 'tags')
filter_horizontal = ('tags',)
Expand Down
4 changes: 2 additions & 2 deletions blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ class Article(BaseModel):
type = models.CharField('类型', max_length=1, choices=TYPE, default='a')
views = models.PositiveIntegerField('浏览量', default=0)
author = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name='作者', on_delete=models.CASCADE)

article_order = models.IntegerField('排序,数字越大越靠前', blank=False, null=False, default=0)
category = models.ForeignKey('Category', verbose_name='分类', on_delete=models.CASCADE, blank=False, null=False)
tags = models.ManyToManyField('Tag', verbose_name='标签集合', blank=True)

def __str__(self):
return self.title

class Meta:
ordering = ['-pub_time']
ordering = ['-article_order', '-pub_time']
verbose_name = "文章"
verbose_name_plural = verbose_name
get_latest_by = 'created_time'
Expand Down