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
8 class TagAdmin(admin.ModelAdmin):
9 list_display = ('name', 'slug', 'sort_key', 'category', 'has_description', 'occurrences')
10 list_filter = ('category',)
11 search_fields = ('name',)
13 readonly_fields = ('occurrences',)
15 def occurrences(self, tag):
16 return tag.items.count()
17 occurrences.short_description = 'Wystąpienia'
19 prepopulated_fields = {'slug': ('name',), 'sort_key': ('name',)}
20 radio_fields = {'category': admin.HORIZONTAL}
23 class MediaInline(admin.TabularInline):
25 readonly_fields = ['source_sha1']
29 class BookAdmin(admin.ModelAdmin):
31 'title', 'slug', 'created_at', 'has_epub_file', 'has_html_file', 'has_description',
33 search_fields = ('title',)
36 inlines = [MediaInline]
39 class FragmentAdmin(admin.ModelAdmin):
40 list_display = ('book', 'anchor',)
41 ordering = ('book', 'anchor',)
44 class CollectionAdmin(admin.ModelAdmin):
45 prepopulated_fields = {'slug': ('title',)}
48 class SourceAdmin(admin.ModelAdmin):
49 list_display = ('netloc', 'name')
52 admin.site.register(Tag, TagAdmin)
53 admin.site.register(Book, BookAdmin)
54 admin.site.register(Fragment, FragmentAdmin)
55 admin.site.register(Collection, CollectionAdmin)
56 admin.site.register(Source, SourceAdmin)