shiftregister/shiftregister/pages/admin.py

36 lines
742 B
Python

from pathlib import Path
from django.contrib import admin
from .models import Page
def reimport(modeladmin, request, queryset):
for page in queryset:
path = Path(__file__).resolve().parent / "default_content" / f"{page.url}.html"
if path.exists():
page.content = path.read_text()
page.save()
@admin.register(Page)
class PageAdmin(admin.ModelAdmin):
fields = (
"url",
"content",
"title",
"visible",
"kind",
"show_in_footer_nav",
"show_in_main_nav",
)
list_display = (
"url",
"title",
"visible",
"kind",
"show_in_footer_nav",
"show_in_main_nav",
)
actions = (reimport,)