shiftregister/shiftregister/pages/admin.py

19 lines
538 B
Python

from django.contrib import admin
from .models import Page
from pathlib import Path
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")
list_display = ("url", "title", "visible", "kind")
actions = (reimport,)