我想通过模型中的函数过滤查询集。
class CommentAdmin(admin.ModelAdmin):
class PostedByGuestFilter(admin.SimpleListFilter):
title = 'Posted by Guest'
parameter_name = 'posted_by_guest'
def lookups(self, request, model_admin):
return (
(True, 'Yes'),
(False, 'No'),
)
def queryset(self, request, queryset):
if self.value():
return [comment for comment in queryset if comment.posted_by_guest()]
elif not self.value():
return [comment for comment in queryset if not comment.posted_by_guest()]
不幸的是,这种实施导致django.admin
告诉我我的数据库已损坏。我该如何解决这个问题?