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 search_fields = ('title',)
46 inlines = [MediaInline]
49 class FragmentAdmin(admin.ModelAdmin):
50 list_display = ('book', 'anchor',)
51 ordering = ('book', 'anchor',)
54 class CollectionAdmin(admin.ModelAdmin):
55 list_display = ('title', 'listed')
56 prepopulated_fields = {'slug': ('title',)}
59 class SourceAdmin(admin.ModelAdmin):
60 list_display = ('netloc', 'name')
63 admin.site.register(Tag, TagAdmin)
64 admin.site.register(Book, BookAdmin)
65 admin.site.register(Fragment, FragmentAdmin)
66 admin.site.register(Collection, CollectionAdmin)
67 admin.site.register(Source, SourceAdmin)