camp/content/admin.py

48 lines
1.3 KiB
Python
Raw Permalink Normal View History

2017-07-03 13:44:07 +05:30
from django import forms
2017-05-20 18:15:26 +05:30
from django.contrib import admin
2017-07-03 13:44:07 +05:30
from markdownx.admin import MarkdownxModelAdmin
from markdownx.widgets import AdminMarkdownxWidget
2017-05-20 18:15:26 +05:30
2017-07-03 13:44:07 +05:30
from photologue.admin import GalleryAdmin as GalleryAdminDefault
from photologue.models import Gallery
2017-12-19 15:02:34 +01:00
from .models import *
2017-06-10 16:37:32 +05:30
2017-06-10 17:35:37 +05:30
class FileInline(admin.StackedInline):
2017-12-19 13:34:43 +00:00
extra = 0
2017-06-10 17:35:37 +05:30
model = File
class LinkInline(admin.StackedInline):
2017-12-19 13:34:43 +00:00
extra = 0
2017-06-10 17:35:37 +05:30
model = Link
2017-05-20 18:15:26 +05:30
2018-08-21 14:22:29 +02:00
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',
)
2017-07-03 13:44:07 +05:30
2017-05-20 18:15:26 +05:30
class ContentAdmin(admin.ModelAdmin):
save_on_top = True
2018-01-01 13:31:30 +00:00
list_display = ('id', '__str__', 'datestart', 'shortname', 'type')
2017-05-24 17:14:04 +05:30
list_filter = ['datestart', 'type']
2017-12-18 12:54:04 +00:00
search_fields = ['title', 'body', 'header', 'shortname']
2025-03-24 10:48:13 +00:00
raw_id_fields = ['photo', 'gallery']
2018-08-22 21:59:40 +02:00
inlines = [FileInline, LinkInline]
2017-07-03 13:44:07 +05:30
formfield_overrides = {
2018-08-21 14:22:29 +02:00
models.TextField: {'widget': MaxLengthAdminMarkdownxWidget},
2017-07-03 13:44:07 +05:30
}
2017-05-24 17:14:04 +05:30
2017-05-20 18:15:26 +05:30
admin.site.register(Content, ContentAdmin)
2017-07-03 13:44:07 +05:30