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 django import forms
7 from catalogue.models import Tag, Book, Fragment, BookMedia, Collection, Source
10 class TagAdmin(admin.ModelAdmin):
11 list_display = ('name', 'slug', 'sort_key', 'category', 'has_description', 'occurrences')
12 list_filter = ('category',)
13 search_fields = ('name',)
15 readonly_fields = ('occurrences',)
17 def occurrences(self, tag):
18 return tag.items.count()
19 occurrences.short_description = 'Wystąpienia'
21 prepopulated_fields = {'slug': ('name',), 'sort_key': ('name',)}
22 radio_fields = {'category': admin.HORIZONTAL}
25 class MediaInline(admin.TabularInline):
27 readonly_fields = ['source_sha1']
31 class BookAdmin(admin.ModelAdmin):
32 list_display = ('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)