You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
from django.contrib import admin
|
|
from django.conf import settings
|
|
from django import forms
|
|
from django.utils.translation import gettext_lazy as _
|
|
from django.db.models import TextField
|
|
from django.forms import Textarea
|
|
|
|
from .models import Post, Image, Section, MemberOnPost, Link
|
|
|
|
|
|
class ImageInline(admin.TabularInline):
|
|
model = Image
|
|
extra = 0
|
|
|
|
|
|
class MemberOnPostInline(admin.TabularInline):
|
|
model = MemberOnPost
|
|
extra = 0
|
|
|
|
|
|
class PostForm(forms.ModelForm):
|
|
urlname = forms.RegexField(regex=r'^{pattern}+$'.format(pattern=settings.STARTPAGE_URL_NAME_PATTERN),
|
|
label=_('URL'),
|
|
error_messages={'invalid': _('The url may only consist of letters, numerals, _, -, :, * and spaces.')})
|
|
|
|
|
|
@admin.register(Post)
|
|
class PostAdmin(admin.ModelAdmin):
|
|
inlines = [ImageInline, MemberOnPostInline]
|
|
list_display = ['title', 'date', 'section', 'absolute_urlname']
|
|
list_filter = ['section']
|
|
search_fields = ['title']
|
|
form = PostForm
|
|
|
|
|
|
class SectionForm(forms.ModelForm):
|
|
urlname = forms.RegexField(regex=r'^{pattern}+$'.format(pattern=settings.STARTPAGE_URL_NAME_PATTERN),
|
|
label=_('URL'),
|
|
error_messages={'invalid': _('The url may only consist of letters, numerals, _, -, :, * and spaces.')})
|
|
|
|
@admin.register(Section)
|
|
class SectionAdmin(admin.ModelAdmin):
|
|
list_display = ['title', 'absolute_urlname']
|
|
form = SectionForm
|
|
|
|
|
|
@admin.register(Link)
|
|
class LinkAdmin(admin.ModelAdmin):
|
|
list_display = ['title', 'url', 'visible']
|
|
|
|
formfield_overrides = {
|
|
TextField: {'widget': Textarea(attrs={'rows': 2, 'cols': 40})}
|
|
}
|
|
|
|
|