+
+
+admin.site.register(models.CollectionCategory)
+
+
+class AuthorInline(admin.TabularInline):
+ model = models.Author.collections.through
+ autocomplete_fields = ["author"]
+
+
+class BookInline(admin.TabularInline):
+ model = models.Book.collections.through
+ autocomplete_fields = ["book"]
+
+
+class CollectionAdmin(admin.ModelAdmin):
+ list_display = ["name"]
+ autocomplete_fields = []
+ prepopulated_fields = {"slug": ("name",)}
+ search_fields = ["name"]
+ fields = ['name', 'slug', 'category', 'notes', 'estimated_costs']
+ readonly_fields = ['estimated_costs']
+ inlines = [AuthorInline, BookInline]
+
+ def estimated_costs(self, obj):
+ return "\n".join(
+ "{}: {} zł".format(
+ work_type.name,
+ cost or '—'
+ )
+ for work_type, cost in obj.get_estimated_costs().items()
+ )
+
+
+admin.site.register(models.Collection, CollectionAdmin)
+
+
+
+class CategoryAdmin(admin.ModelAdmin):
+ search_fields = ["name"]
+
+admin.site.register(models.Epoch, CategoryAdmin)
+admin.site.register(models.Genre, CategoryAdmin)
+admin.site.register(models.Kind, CategoryAdmin)
+
+
+
+class WorkRateInline(admin.TabularInline):
+ model = models.WorkRate
+ autocomplete_fields = ['kinds', 'genres', 'epochs', 'collections']
+
+
+class WorkTypeAdmin(admin.ModelAdmin):
+ inlines = [WorkRateInline]
+
+admin.site.register(models.WorkType, WorkTypeAdmin)
+