# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from django.contrib import admin
-from django import forms
+from catalogue.models import Tag, Book, Fragment, BookMedia, Collection, Source, Snippet
+from pz.admin import EmptyFieldListFilter
-from newtagging.admin import TaggableModelAdmin, TaggableModelForm
-from catalogue.models import Tag, Book, Fragment, BookMedia, Collection, Source
+
+class BlankFieldListFilter(EmptyFieldListFilter):
+ with_empty_str = True
class TagAdmin(admin.ModelAdmin):
search_fields = ('name',)
ordering = ('name',)
readonly_fields = ('occurrences',)
+ raw_id_fields = ['user']
def occurrences(self, tag):
return tag.items.count()
- occurrences.short_description = u'Wystąpienia'
+ occurrences.short_description = 'Wystąpienia'
prepopulated_fields = {'slug': ('name',), 'sort_key': ('name',)}
radio_fields = {'category': admin.HORIZONTAL}
extra = 0
-#FIXME: Taggable admin is broken.
-#class BookAdmin(TaggableModelAdmin):
class BookAdmin(admin.ModelAdmin):
- #tag_model = Tag
- #form = TaggableModelForm
-
- list_display = ('title', 'slug', 'created_at', 'has_epub_file', 'has_html_file', 'has_description',)
+ list_display = (
+ 'title', 'slug', 'created_at', 'has_epub_file', 'has_html_file', 'has_description',
+ )
+ list_filter = [
+ 'print_on_demand',
+ ('wiki_link', BlankFieldListFilter),
+ ('parent', EmptyFieldListFilter),
+ ('media', admin.EmptyFieldListFilter),
+ ]
+ date_hierarchy = 'created_at'
search_fields = ('title',)
ordering = ('title',)
inlines = [MediaInline]
-#FIXME: Taggable admin is broken.
-#class FragmentAdmin(TaggableModelAdmin):
class FragmentAdmin(admin.ModelAdmin):
- #tag_model = Tag
-
list_display = ('book', 'anchor',)
ordering = ('book', 'anchor',)
class CollectionAdmin(admin.ModelAdmin):
+ list_display = ('title', 'listed', 'role')
prepopulated_fields = {'slug': ('title',)}
admin.site.register(Fragment, FragmentAdmin)
admin.site.register(Collection, CollectionAdmin)
admin.site.register(Source, SourceAdmin)
+
+
+admin.site.register(Snippet)