2019-03-27 15:49:14 +00:00
|
|
|
from django.contrib import admin
|
|
|
|
from django.utils.text import Truncator
|
|
|
|
from django.utils.safestring import mark_safe
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
2020-01-02 00:56:15 +00:00
|
|
|
from .models import Config
|
2019-08-25 21:36:58 +00:00
|
|
|
|
2020-01-02 00:56:15 +00:00
|
|
|
class BasePageAdmin(admin.ModelAdmin):
|
2019-03-27 15:49:14 +00:00
|
|
|
prepopulated_fields = {'slug': ('title',)}
|
|
|
|
|
2019-12-31 12:05:12 +00:00
|
|
|
class BaseSectionAdmin(admin.ModelAdmin):
|
2019-08-27 13:01:45 +00:00
|
|
|
list_filter = [
|
|
|
|
('page', admin.RelatedOnlyFieldListFilter),
|
|
|
|
]
|
2019-08-27 12:25:55 +00:00
|
|
|
list_display = ['__str__', 'get_type_display']
|
2019-08-25 21:36:58 +00:00
|
|
|
|
2019-03-27 15:49:14 +00:00
|
|
|
@admin.register(Config)
|
|
|
|
class ConfigAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ['__str__', 'get_content']
|
|
|
|
exclude = ['parameter']
|
|
|
|
|
|
|
|
def get_content(self, obj):
|
|
|
|
return mark_safe(Truncator(obj.content).words(50, html=True))
|
|
|
|
get_content.short_description = _('content')
|
|
|
|
|
|
|
|
def has_add_permission(self, request):
|
|
|
|
return False
|
|
|
|
|
|
|
|
def has_delete_permission(self, *args, **kwargs):
|
|
|
|
return False
|