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 newtagging.admin import TaggableModelAdmin, TaggableModelForm
8 from catalogue.models import Tag, Book, Fragment, BookMedia, Collection, Source
11 class TagAdmin(admin.ModelAdmin):
12 list_display = ('name', 'slug', 'sort_key', 'category', 'has_description', 'occurrences')
13 list_filter = ('category',)
14 search_fields = ('name',)
16 readonly_fields = ('occurrences',)
18 def occurrences(self, tag):
19 return tag.items.count()
20 occurrences.short_description = u'Wystąpienia'
22 prepopulated_fields = {'slug': ('name',), 'sort_key': ('name',)}
23 radio_fields = {'category': admin.HORIZONTAL}
26 class MediaInline(admin.TabularInline):
28 readonly_fields = ['source_sha1']
32 #FIXME: Taggable admin is broken.
33 #class BookAdmin(TaggableModelAdmin):
34 class BookAdmin(admin.ModelAdmin):
36 #form = TaggableModelForm
38 list_display = ('title', 'slug', 'created_at', 'has_epub_file', 'has_html_file', 'has_description',)
39 search_fields = ('title',)
42 inlines = [MediaInline]
45 #FIXME: Taggable admin is broken.
46 #class FragmentAdmin(TaggableModelAdmin):
47 class FragmentAdmin(admin.ModelAdmin):
50 list_display = ('book', 'anchor',)
51 ordering = ('book', 'anchor',)
54 class CollectionAdmin(admin.ModelAdmin):
55 prepopulated_fields = {'slug': ('title',)}
58 class SourceAdmin(admin.ModelAdmin):
59 list_display = ('netloc', 'name')
62 admin.site.register(Tag, TagAdmin)
63 admin.site.register(Book, BookAdmin)
64 admin.site.register(Fragment, FragmentAdmin)
65 admin.site.register(Collection, CollectionAdmin)
66 admin.site.register(Source, SourceAdmin)