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

admin优化 #747

Merged
merged 1 commit into from
Nov 28, 2024
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
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
Loading