1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from django.contrib import admin
5 from catalogue.models import Tag, Book, Fragment, BookMedia, Collection, Source
6 from pz.admin import EmptyFieldListFilter
9 class BlankFieldListFilter(EmptyFieldListFilter):
13 class TagAdmin(admin.ModelAdmin):
14 list_display = ('name', 'slug', 'sort_key', 'category', 'has_description', 'occurrences')
15 list_filter = ('category',)
16 search_fields = ('name',)
18 readonly_fields = ('occurrences',)
20 def occurrences(self, tag):
21 return tag.items.count()
22 occurrences.short_description = 'Wystąpienia'
24 prepopulated_fields = {'slug': ('name',), 'sort_key': ('name',)}
25 radio_fields = {'category': admin.HORIZONTAL}
28 class MediaInline(admin.TabularInline):
30 readonly_fields = ['source_sha1']
34 class BookAdmin(admin.ModelAdmin):
36 'title', 'slug', 'created_at', 'has_epub_file', 'has_html_file', 'has_description',
40 ('wiki_link', BlankFieldListFilter),
41 ('parent', EmptyFieldListFilter),
43 date_hierarchy = 'created_at'
44 search_fields = ('title',)
47 inlines = [MediaInline]
50 class FragmentAdmin(admin.ModelAdmin):
51 list_display = ('book', 'anchor',)
52 ordering = ('book', 'anchor',)
55 class CollectionAdmin(admin.ModelAdmin):
56 list_display = ('title', 'listed', 'role')
57 prepopulated_fields = {'slug': ('title',)}
60 class SourceAdmin(admin.ModelAdmin):
61 list_display = ('netloc', 'name')
64 admin.site.register(Tag, TagAdmin)
65 admin.site.register(Book, BookAdmin)
66 admin.site.register(Fragment, FragmentAdmin)
67 admin.site.register(Collection, CollectionAdmin)
68 admin.site.register(Source, SourceAdmin)