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 list_filter = ['print_on_demand']
34 search_fields = ('title',)
37 inlines = [MediaInline]
40 class FragmentAdmin(admin.ModelAdmin):
41 list_display = ('book', 'anchor',)
42 ordering = ('book', 'anchor',)
45 class CollectionAdmin(admin.ModelAdmin):
46 prepopulated_fields = {'slug': ('title',)}
49 class SourceAdmin(admin.ModelAdmin):
50 list_display = ('netloc', 'name')
53 admin.site.register(Tag, TagAdmin)
54 admin.site.register(Book, BookAdmin)
55 admin.site.register(Fragment, FragmentAdmin)
56 admin.site.register(Collection, CollectionAdmin)
57 admin.site.register(Source, SourceAdmin)