Skip to content

Commit

Permalink
admin优化
Browse files Browse the repository at this point in the history
  • Loading branch information
liangliangyy committed Nov 28, 2024
1 parent cff986b commit 0938a8d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
21 changes: 2 additions & 19 deletions blog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,12 @@
from django.contrib.auth import get_user_model
from django.urls import reverse
from django.utils.html import format_html
from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext_lazy as _

# Register your models here.
from .models import Article


class ArticleListFilter(admin.SimpleListFilter):
title = _("author")
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):
# body = forms.CharField(widget=AdminPagedownWidget())

Expand Down Expand Up @@ -71,7 +54,7 @@ class ArticlelAdmin(admin.ModelAdmin):
'type',
'article_order')
list_display_links = ('id', 'title')
list_filter = (ArticleListFilter, 'status', 'type', 'category', 'tags')
list_filter = ('status', 'type', 'category')
filter_horizontal = ('tags',)
exclude = ('creation_time', 'last_modify_time')
view_on_site = True
Expand Down
2 changes: 1 addition & 1 deletion comments/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CommentAdmin(admin.ModelAdmin):
'is_enable',
'creation_time')
list_display_links = ('id', 'body', 'is_enable')
list_filter = ('is_enable', 'author', 'article',)
list_filter = ('is_enable',)
exclude = ('creation_time', 'last_modify_time')
actions = [disable_commentstatus, enable_commentstatus]

Expand Down

0 comments on commit 0938a8d

Please sign in to comment.