Skip to content

Commit

Permalink
Merge pull request #11 from liangliangyy/dev
Browse files Browse the repository at this point in the history
修改sitemap以及管理后台用户过滤功能
  • Loading branch information
liangliangyy committed Apr 6, 2017
2 parents 1a31513 + ae079aa commit 4602718
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DjangoBlog/sitemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 19 additions & 1 deletion blog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@
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):
Expand All @@ -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')

Expand Down

0 comments on commit 4602718

Please sign in to comment.