From ae079aa000bad0ff772fc376e198fa7fd7990e37 Mon Sep 17 00:00:00 2001 From: liangliangyy Date: Thu, 6 Apr 2017 15:00:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9sitemap=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=90=8E=E5=8F=B0=E7=94=A8=E6=88=B7=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DjangoBlog/sitemap.py | 2 +- blog/admin.py | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/DjangoBlog/sitemap.py b/DjangoBlog/sitemap.py index ae7d3db..18e11ed 100644 --- a/DjangoBlog/sitemap.py +++ b/DjangoBlog/sitemap.py @@ -69,7 +69,7 @@ class UserSiteMap(Sitemap): priority = "0.3" def items(self): - return BlogUser.objects.all() + return list(set(map(lambda x: x.author, Article.objects.all()))) def lastmod(self, obj): return obj.date_joined diff --git a/blog/admin.py b/blog/admin.py index b4173d7..9bf31e0 100644 --- a/blog/admin.py +++ b/blog/admin.py @@ -4,6 +4,24 @@ from django.contrib import admin from .models import Article, Category, Tag, Links from pagedown.widgets import AdminPagedownWidget from django import forms +from django.utils.translation import ugettext_lazy as _ + + +class ArticleListFilter(admin.SimpleListFilter): + title = _("作者") + parameter_name = 'author' + + def lookups(self, request, model_admin): + authors = list(set(map(lambda x: x.author, Article.objects.all()))) + for author in authors: + yield (author.id, _(author.username)) + + def queryset(self, request, queryset): + id = self.value() + if id: + return queryset.filter(author__id__exact=id) + else: + return queryset class ArticleForm(forms.ModelForm): @@ -18,7 +36,7 @@ class ArticlelAdmin(admin.ModelAdmin): form = ArticleForm list_display = ('id', 'title', 'author', 'created_time', 'views', 'status', 'type') list_display_links = ('id', 'title') - list_filter = ('author', 'status', 'type', 'category', 'tags') + list_filter = (ArticleListFilter, 'status', 'type', 'category', 'tags') filter_horizontal = ('tags',) exclude = ('slug', 'created_time')