teaser maxlength
This commit is contained in:
parent
ab7a4d3b99
commit
823f763c98
|
@ -39,6 +39,20 @@ class ServerAdmin(admin.ModelAdmin):
|
|||
pass
|
||||
'''
|
||||
|
||||
class MaxLengthAdminMarkdownxWidget(AdminMarkdownxWidget):
|
||||
def get_context(self, name, value, attrs=None):
|
||||
if name == 'teaser':
|
||||
if not attrs:
|
||||
attrs = {}
|
||||
attrs['maxlength'] = 250
|
||||
print(dir(self))
|
||||
return super(MaxLengthAdminMarkdownxWidget, self).get_context(name, value, attrs)
|
||||
|
||||
class Media:
|
||||
js = (
|
||||
'js/maxlength_count.js',
|
||||
)
|
||||
|
||||
class GalleryAdminForm(forms.ModelForm):
|
||||
"""Users never need to enter a description on a gallery."""
|
||||
|
||||
|
@ -58,7 +72,7 @@ class ContentAdmin(admin.ModelAdmin):
|
|||
raw_id_fields = ['photo']
|
||||
inlines = [ContentParentsInline, FileInline, LinkInline]
|
||||
formfield_overrides = {
|
||||
models.TextField: {'widget': AdminMarkdownxWidget},
|
||||
models.TextField: {'widget': MaxLengthAdminMarkdownxWidget},
|
||||
}
|
||||
|
||||
|
||||
|
|
18
content/static/js/maxlength_count.js
Normal file
18
content/static/js/maxlength_count.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
django.jQuery(function() {
|
||||
django.jQuery('textarea[maxlength]').each(function(i, textarea) {
|
||||
var t = django.jQuery(textarea),
|
||||
count = t.parent().find('.maxlength-count')
|
||||
if (count.length == 0) {
|
||||
count = django.jQuery('<div>', {'class': 'maxlength-count'} ).insertAfter(t)
|
||||
t.on({
|
||||
keydown: update,
|
||||
change: update,
|
||||
drop: update,
|
||||
})
|
||||
}
|
||||
function update() {
|
||||
var max = Math.round(t.attr('maxlength')), left = max - t.val().length
|
||||
count.html(left + ' characters left. (max: ' + max + ')')
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user