From 4ee3d412374615878a5bed06c56324831e6ab00b Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 13 Aug 2019 23:17:56 +0200 Subject: [PATCH] =?UTF-8?q?Polymorfi=C4=8Dt=C3=AD=20admini=20pro=20TreeNod?= =?UTF-8?q?y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/admin.py | 89 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 11 deletions(-) diff --git a/seminar/admin.py b/seminar/admin.py index d02b4db7..0a66f30f 100644 --- a/seminar/admin.py +++ b/seminar/admin.py @@ -1,5 +1,7 @@ from django.contrib import admin +from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin, PolymorphicChildModelFilter + import seminar.models as m admin.site.register(m.Osoba) @@ -10,27 +12,92 @@ admin.site.register(m.Rocnik) admin.site.register(m.Cislo) admin.site.register(m.Organizator) admin.site.register(m.Soustredeni) + +# TODO: Polymorphic admin admin.site.register(m.Problem) admin.site.register(m.Tema) admin.site.register(m.Clanek) admin.site.register(m.Text) admin.site.register(m.Uloha) +# END TODO. + admin.site.register(m.Reseni) admin.site.register(m.Hodnoceni) admin.site.register(m.PrilohaReseni) admin.site.register(m.Pohadka) admin.site.register(m.Konfera) admin.site.register(m.Obrazek) -admin.site.register(m.TreeNode) -admin.site.register(m.RocnikNode) -admin.site.register(m.CisloNode) -admin.site.register(m.MezicisloNode) -admin.site.register(m.TemaVCisleNode) -admin.site.register(m.KonferaNode) -admin.site.register(m.ClanekNode) -admin.site.register(m.UlohaZadaniNode) -admin.site.register(m.PohadkaNode) -admin.site.register(m.UlohaVzorakNode) -admin.site.register(m.TextNode) + + +# 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.KonferaNode, + m.ClanekNode, + m.UlohaZadaniNode, + m.PohadkaNode, + m.UlohaVzorakNode, + m.TextNode, + ] + +@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.KonferaNode) +class KonferaNodeAdmin(PolymorphicChildModelAdmin): + base_model = m.KonferaNode + show_in_index = True + +@admin.register(m.ClanekNode) +class ClanekNodeAdmin(PolymorphicChildModelAdmin): + base_model = m.ClanekNode + 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.site.register(m.Nastaveni) admin.site.register(m.Novinky)