"Show Count" on ThingAdmin fixed
This commit is contained in:
@@ -1,10 +1,43 @@
|
||||
from django import forms
|
||||
from django.contrib import admin
|
||||
from django.contrib.admin import SimpleListFilter
|
||||
from django.utils.html import format_html
|
||||
|
||||
from .models import Box, BoxType, Facet, Tag, Thing, ThingFile, ThingLink
|
||||
|
||||
|
||||
class BoxFilter(SimpleListFilter):
|
||||
"""Custom filter for boxes using pk to avoid spaces in aliases."""
|
||||
|
||||
title = 'box'
|
||||
parameter_name = 'box__pk'
|
||||
|
||||
def lookups(self, request, model_admin):
|
||||
boxes = Box.objects.select_related('box_type').order_by('id')
|
||||
return [(box.pk, str(box)) for box in boxes]
|
||||
|
||||
def queryset(self, request, queryset):
|
||||
if self.value():
|
||||
return queryset.filter(box__pk=self.value())
|
||||
return queryset
|
||||
|
||||
|
||||
class TagsFilter(SimpleListFilter):
|
||||
"""Custom filter for tags using pk to avoid spaces in aliases."""
|
||||
|
||||
title = 'tags'
|
||||
parameter_name = 'tags__pk'
|
||||
|
||||
def lookups(self, request, model_admin):
|
||||
tags = Tag.objects.select_related('facet').order_by('facet__name', 'name')
|
||||
return [(tag.pk, str(tag)) for tag in tags]
|
||||
|
||||
def queryset(self, request, queryset):
|
||||
if self.value():
|
||||
return queryset.filter(tags__pk=self.value())
|
||||
return queryset
|
||||
|
||||
|
||||
@admin.register(BoxType)
|
||||
class BoxTypeAdmin(admin.ModelAdmin):
|
||||
"""Admin configuration for BoxType model."""
|
||||
@@ -42,7 +75,7 @@ class ThingAdmin(admin.ModelAdmin):
|
||||
"""Admin configuration for Thing model."""
|
||||
|
||||
list_display = ('name', 'box')
|
||||
list_filter = ('box', 'tags')
|
||||
list_filter = (BoxFilter, TagsFilter)
|
||||
search_fields = ('name', 'description')
|
||||
filter_horizontal = ('tags',)
|
||||
inlines = [ThingFileInline, ThingLinkInline]
|
||||
|
||||
Reference in New Issue
Block a user