from django.contrib import admin from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin import seminar.models as m # Polymorfismus pro stromy # TODO: Inlines podle https://django-polymorphic.readthedocs.io/en/stable/admin.html @admin.register(m.TreeNode) class TreeNodeAdmin(PolymorphicParentModelAdmin): base_model = m.TreeNode child_models = [ m.RocnikNode, m.CisloNode, m.MezicisloNode, m.TemaVCisleNode, m.UlohaZadaniNode, m.PohadkaNode, m.UlohaVzorakNode, m.TextNode, m.CastNode, m.OrgTextNode, ] actions = ['aktualizuj_nazvy'] # XXX: nejspíš je to totální DB HOG, nechcete to použít moc často. def aktualizuj_nazvy(self, request, queryset): newqs = queryset.get_real_instances() for tn in newqs: tn.aktualizuj_nazev() tn.save() self.message_user(request, "Názvy aktualizovány.") aktualizuj_nazvy.short_description = "Aktualizuj vybraným TreeNodům názvy" @admin.register(m.RocnikNode) class RocnikNodeAdmin(PolymorphicChildModelAdmin): base_model = m.RocnikNode show_in_index = True @admin.register(m.CisloNode) class CisloNodeAdmin(PolymorphicChildModelAdmin): base_model = m.CisloNode show_in_index = True @admin.register(m.MezicisloNode) class MezicisloNodeAdmin(PolymorphicChildModelAdmin): base_model = m.MezicisloNode show_in_index = True @admin.register(m.TemaVCisleNode) class TemaVCisleNodeAdmin(PolymorphicChildModelAdmin): base_model = m.TemaVCisleNode show_in_index = True @admin.register(m.UlohaZadaniNode) class UlohaZadaniNodeAdmin(PolymorphicChildModelAdmin): base_model = m.UlohaZadaniNode show_in_index = True @admin.register(m.PohadkaNode) class PohadkaNodeAdmin(PolymorphicChildModelAdmin): base_model = m.PohadkaNode show_in_index = True @admin.register(m.UlohaVzorakNode) class UlohaVzorakNodeAdmin(PolymorphicChildModelAdmin): base_model = m.UlohaVzorakNode show_in_index = True @admin.register(m.TextNode) class TextNodeAdmin(PolymorphicChildModelAdmin): base_model = m.TextNode show_in_index = True @admin.register(m.CastNode) class TextNodeAdmin(PolymorphicChildModelAdmin): base_model = m.CastNode show_in_index = True fields = ('nadpis',) @admin.register(m.OrgTextNode) class TextNodeAdmin(PolymorphicChildModelAdmin): base_model = m.OrgTextNode show_in_index = True