#
from django.contrib import admin
from catalogue.models import Tag, Book, Fragment, BookMedia, Collection, Source
+from pz.admin import EmptyFieldListFilter
+
+
+class BlankFieldListFilter(EmptyFieldListFilter):
+ with_empty_str = True
class TagAdmin(admin.ModelAdmin):
list_display = (
'title', 'slug', 'created_at', 'has_epub_file', 'has_html_file', 'has_description',
)
- list_filter = ['print_on_demand']
+ list_filter = [
+ 'print_on_demand',
+ ('wiki_link', BlankFieldListFilter),
+ ]
search_fields = ('title',)
ordering = ('title',)
state['amount'] = \
self.cleaned_data[f'{which}_amount'] or \
self.cleaned_data['custom_amount'] or \
- self.cleaned_data[f'{monthly}_amount_selected']
+ self.cleaned_data[f'{which}_amount_selected']
return state
# Backport from Django 3.1.
class EmptyFieldListFilter(FieldListFilter):
+ with_empty_str = False
+
def __init__(self, field, request, params, model, model_admin, field_path):
self.lookup_kwarg = '%s__isempty' % field_path
self.lookup_val = params.get(self.lookup_kwarg)
raise IncorrectLookupParameters
lookup_condition = Q(**{'%s__isnull' % self.field_path: True})
+ if self.with_empty_str:
+ lookup_condition |= Q(**{self.field_path: ''})
if self.lookup_val == '1':
return queryset.filter(lookup_condition)
return queryset.exclude(lookup_condition)