camp/content/admin.py

82 lines
2.0 KiB
Python
Raw Permalink Normal View History

2017-05-20 12:45:26 +00:00
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
2017-07-03 08:14:07 +00:00
from django import forms
2017-05-20 12:45:26 +00:00
from django.contrib import admin
2017-07-03 08:14:07 +00:00
from markdownx.admin import MarkdownxModelAdmin
from markdownx.widgets import AdminMarkdownxWidget
2017-05-20 12:45:26 +00:00
2017-07-03 08:14:07 +00:00
from photologue.admin import GalleryAdmin as GalleryAdminDefault
from photologue.models import Gallery
2017-12-19 14:02:34 +00:00
from .models import *
2017-06-10 11:07:32 +00:00
class ContentParentsInline(admin.TabularInline):
model = ContentContent
2017-06-10 12:05:37 +00:00
fk_name = 'contentid2'
2017-12-18 12:54:04 +00:00
raw_id_fields = ['contentid1']
2017-12-19 13:34:43 +00:00
extra = 0
2017-06-10 12:05:37 +00:00
class ImagesInline(admin.StackedInline):
2017-12-19 13:34:43 +00:00
extra = 0
2017-06-10 12:05:37 +00:00
model = Image
class FileInline(admin.StackedInline):
2017-12-19 13:34:43 +00:00
extra = 0
2017-06-10 12:05:37 +00:00
model = File
class LinkInline(admin.StackedInline):
2017-12-19 13:34:43 +00:00
extra = 0
2017-06-10 12:05:37 +00:00
model = Link
2017-05-20 12:45:26 +00:00
'''
class SubdomainInline(admin.StackedInline):
model = Subdomain
class DomainAliasInline(admin.StackedInline):
model = DomainAlias
class ServerAdmin(admin.ModelAdmin):
pass
'''
2018-08-21 12:22:29 +00: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 08:14:07 +00:00
class GalleryAdminForm(forms.ModelForm):
"""Users never need to enter a description on a gallery."""
class Meta:
model = Gallery
exclude = ['description']
class GalleryAdmin(GalleryAdminDefault):
form = GalleryAdminForm
2017-05-20 12:45:26 +00:00
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 11:44:04 +00:00
list_filter = ['datestart', 'type']
2017-12-18 12:54:04 +00:00
search_fields = ['title', 'body', 'header', 'shortname']
2018-02-22 13:31:52 +00:00
raw_id_fields = ['photo']
2018-08-22 19:59:40 +00:00
inlines = [FileInline, LinkInline]
2017-07-03 08:14:07 +00:00
formfield_overrides = {
2018-08-21 12:22:29 +00:00
models.TextField: {'widget': MaxLengthAdminMarkdownxWidget},
2017-07-03 08:14:07 +00:00
}
2017-05-24 11:44:04 +00:00
2017-05-20 12:45:26 +00:00
admin.site.register(Content, ContentAdmin)
2017-07-03 08:14:07 +00:00
admin.site.unregister(Gallery)
admin.site.register(Gallery, GalleryAdmin)