mamweb/treenode/admin.py

106 lines
2.8 KiB
Python
Raw Normal View History

2021-11-07 10:25:34 +01:00
from django.contrib import admin
2024-08-04 19:01:09 +02:00
from django.db import models
from django.forms import widgets
2021-11-07 10:25:34 +01:00
from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin, PolymorphicChildModelFilter
2024-11-05 15:07:51 +01:00
from .models import TreeNode, RocnikNode, CisloNode, MezicisloNode, TemaVCisleNode, UlohaZadaniNode, PohadkaNode, UlohaVzorakNode, TextNode, CastNode, OrgTextNode, ReseniNode
from .models import Text, Obrazek
2021-11-07 10:25:34 +01:00
# Polymorfismus pro stromy
# TODO: Inlines podle https://django-polymorphic.readthedocs.io/en/stable/admin.html
2024-11-01 13:50:48 +01:00
@admin.register(TreeNode)
2021-11-07 10:25:34 +01:00
class TreeNodeAdmin(PolymorphicParentModelAdmin):
2024-11-01 13:50:48 +01:00
base_model = TreeNode
child_models = [
2024-11-01 13:50:48 +01:00
RocnikNode,
CisloNode,
MezicisloNode,
TemaVCisleNode,
UlohaZadaniNode,
PohadkaNode,
UlohaVzorakNode,
TextNode,
CastNode,
OrgTextNode,
2024-11-05 15:07:51 +01:00
ReseniNode,
]
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"
2021-11-07 10:25:34 +01:00
2024-11-01 13:50:48 +01:00
@admin.register(RocnikNode)
2021-11-07 10:25:34 +01:00
class RocnikNodeAdmin(PolymorphicChildModelAdmin):
2024-11-01 13:50:48 +01:00
base_model = RocnikNode
show_in_index = True
2021-11-07 10:25:34 +01:00
2024-11-01 13:50:48 +01:00
@admin.register(CisloNode)
2021-11-07 10:25:34 +01:00
class CisloNodeAdmin(PolymorphicChildModelAdmin):
2024-11-01 13:50:48 +01:00
base_model = CisloNode
show_in_index = True
2021-11-07 10:25:34 +01:00
2024-11-01 13:50:48 +01:00
@admin.register(MezicisloNode)
2021-11-07 10:25:34 +01:00
class MezicisloNodeAdmin(PolymorphicChildModelAdmin):
2024-11-01 13:50:48 +01:00
base_model = MezicisloNode
show_in_index = True
2021-11-07 10:25:34 +01:00
2024-11-01 13:50:48 +01:00
@admin.register(TemaVCisleNode)
2021-11-07 10:25:34 +01:00
class TemaVCisleNodeAdmin(PolymorphicChildModelAdmin):
2024-11-01 13:50:48 +01:00
base_model = TemaVCisleNode
show_in_index = True
2021-11-07 10:25:34 +01:00
2024-11-01 13:50:48 +01:00
@admin.register(UlohaZadaniNode)
2021-11-07 10:25:34 +01:00
class UlohaZadaniNodeAdmin(PolymorphicChildModelAdmin):
2024-11-01 13:50:48 +01:00
base_model = UlohaZadaniNode
show_in_index = True
2021-11-07 10:25:34 +01:00
2024-11-01 13:50:48 +01:00
@admin.register(PohadkaNode)
2021-11-07 10:25:34 +01:00
class PohadkaNodeAdmin(PolymorphicChildModelAdmin):
2024-11-01 13:50:48 +01:00
base_model = PohadkaNode
show_in_index = True
2021-11-07 10:25:34 +01:00
2024-11-01 13:50:48 +01:00
@admin.register(UlohaVzorakNode)
2021-11-07 10:25:34 +01:00
class UlohaVzorakNodeAdmin(PolymorphicChildModelAdmin):
2024-11-01 13:50:48 +01:00
base_model = UlohaVzorakNode
show_in_index = True
2021-11-07 10:25:34 +01:00
2024-11-01 13:50:48 +01:00
@admin.register(TextNode)
2021-11-07 10:25:34 +01:00
class TextNodeAdmin(PolymorphicChildModelAdmin):
2024-11-01 13:50:48 +01:00
base_model = TextNode
show_in_index = True
2021-11-07 10:25:34 +01:00
2024-11-01 13:50:48 +01:00
@admin.register(CastNode)
2021-11-07 10:25:34 +01:00
class TextNodeAdmin(PolymorphicChildModelAdmin):
2024-11-01 13:50:48 +01:00
base_model = CastNode
show_in_index = True
fields = ('nadpis',)
2021-11-07 10:25:34 +01:00
2024-11-01 13:50:48 +01:00
@admin.register(OrgTextNode)
2021-11-07 10:25:34 +01:00
class TextNodeAdmin(PolymorphicChildModelAdmin):
2024-11-01 13:50:48 +01:00
base_model = OrgTextNode
show_in_index = True
2021-11-07 10:25:34 +01:00
2024-11-05 15:07:51 +01:00
@admin.register(ReseniNode)
class ReseniNodeAdmin(PolymorphicChildModelAdmin):
base_model = ReseniNode
show_in_index = True
2021-11-07 10:25:34 +01:00
2024-08-04 19:01:09 +02:00
class TextAdminInline(admin.TabularInline):
2024-11-01 13:50:48 +01:00
model = Text
2024-08-04 19:01:09 +02:00
formfield_overrides = {
models.TextField: {'widget': widgets.TextInput}
}
exclude = ['text_zkraceny_set', 'text_zkraceny']
2024-11-01 13:50:48 +01:00
admin.site.register(Text)
admin.site.register(Obrazek)