from django import forms from django.contrib import admin from markdownx.admin import MarkdownxModelAdmin from markdownx.widgets import AdminMarkdownxWidget from photologue.admin import GalleryAdmin as GalleryAdminDefault from photologue.models import Gallery from .models import * class FileInline(admin.StackedInline): extra = 0 model = File class LinkInline(admin.StackedInline): extra = 0 model = Link class MaxLengthAdminMarkdownxWidget(AdminMarkdownxWidget): def get_context(self, name, value, attrs=None): if name == 'teaser': if not attrs: attrs = {} attrs['maxlength'] = 250 return super(MaxLengthAdminMarkdownxWidget, self).get_context(name, value, attrs) class Media: js = ( 'js/maxlength_count.js', ) class ContentAdmin(admin.ModelAdmin): save_on_top = True list_display = ('id', '__str__', 'datestart', 'shortname', 'type') list_filter = ['datestart', 'type'] search_fields = ['title', 'body', 'header', 'shortname'] raw_id_fields = ['photo', 'gallery'] inlines = [FileInline, LinkInline] formfield_overrides = { models.TextField: {'widget': MaxLengthAdminMarkdownxWidget}, } admin.site.register(Content, ContentAdmin)