This commit is contained in:
Iacopo Spalletti 2015-07-04 12:48:59 +02:00
parent d6adc3eab5
commit 95246ff7d8
2 changed files with 15 additions and 22 deletions

View file

@ -1,13 +1,14 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from copy import deepcopy
from admin_enhancer.admin import EnhancedModelAdminMixin from admin_enhancer.admin import EnhancedModelAdminMixin
from cms.admin.placeholderadmin import PlaceholderAdminMixin, FrontendEditableAdminMixin from cms.admin.placeholderadmin import PlaceholderAdminMixin, FrontendEditableAdminMixin
from copy import deepcopy from django import forms
from django.contrib import admin
from django.conf import settings from django.conf import settings
from django.contrib import admin
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from parler.admin import TranslatableAdmin from parler.admin import TranslatableAdmin
from .forms import PostAdminForm
from .models import Post, BlogCategory from .models import Post, BlogCategory
from .settings import get_setting from .settings import get_setting
@ -24,8 +25,7 @@ class BlogCategoryAdmin(EnhancedModelAdminMixin, TranslatableAdmin):
class PostAdmin(EnhancedModelAdminMixin, FrontendEditableAdminMixin, class PostAdmin(EnhancedModelAdminMixin, FrontendEditableAdminMixin,
PlaceholderAdminMixin, TranslatableAdmin, admin.ModelAdmin): PlaceholderAdminMixin, TranslatableAdmin):
form = PostAdminForm
list_display = ['title', 'author', 'date_published', 'date_published_end'] list_display = ['title', 'author', 'date_published', 'date_published_end']
date_hierarchy = 'date_published' date_hierarchy = 'date_published'
raw_id_fields = ['author'] raw_id_fields = ['author']
@ -50,6 +50,16 @@ class PostAdmin(EnhancedModelAdminMixin, FrontendEditableAdminMixin,
}), }),
] ]
def formfield_for_dbfield(self, db_field, **kwargs):
field = super(PostAdmin, self).formfield_for_dbfield(db_field, **kwargs)
if db_field.name == 'meta_description':
original_attrs = field.widget.attrs
original_attrs['maxlength'] = 160
field.widget = forms.TextInput(original_attrs)
elif db_field.name == 'meta_title':
field.max_length = 70
return field
def get_fieldsets(self, request, obj=None): def get_fieldsets(self, request, obj=None):
fsets = deepcopy(self._fieldsets) fsets = deepcopy(self._fieldsets)
if not get_setting('USE_PLACEHOLDER'): if not get_setting('USE_PLACEHOLDER'):

View file

@ -1,11 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django import forms from django import forms
from django.conf import settings from django.conf import settings
from parler.forms import TranslatableModelForm
from taggit_autosuggest.widgets import TagAutoSuggest from taggit_autosuggest.widgets import TagAutoSuggest
from .models import Post
class LatestEntriesForm(forms.ModelForm): class LatestEntriesForm(forms.ModelForm):
@ -18,17 +15,3 @@ class LatestEntriesForm(forms.ModelForm):
'all': ('%sdjangocms_blog/css/%s' % (settings.STATIC_URL, 'all': ('%sdjangocms_blog/css/%s' % (settings.STATIC_URL,
'djangocms_blog_admin.css'),) 'djangocms_blog_admin.css'),)
} }
class PostAdminForm(TranslatableModelForm):
def __init__(self, *args, **kwargs):
super(PostAdminForm, self).__init__(*args, **kwargs)
original_attrs = self.fields['meta_description'].widget.attrs
original_attrs['maxlength'] = 160
self.fields['meta_description'].widget = forms.TextInput(original_attrs)
self.fields['meta_title'].max_length = 70
class Meta:
model = Post
exclude = ()