I'm currently having issues using the TinyMCE editor within the Django admin interface. When entering text into two particular TinyMCE fields and pressing save, the form is returned with both fields empty, flagged red and tagged with a "This field is required" label:
This behaviour is odd, as I have implemented various TinyMCE editors within different models which have worked perfectly. I should clarify that I wish for both fields to be mandatory. The problem is that the text entered is being discarded, and the form is returned with both fields empty. Here is all of the relevant code:
companycms/news/models.py
from django.db import models
from tinymce import models as tinymce_models
class Article(models.Model):
headline = models.CharField(max_length=200)
content = tinymce_models.HTMLField()
about = tinymce_models.HTMLField()
pub_date = models.DateTimeField('date published')
url = models.CharField(max_length=200)
companycms/news/forms.py
from django import forms
from django.db.models import get_model
from django.contrib.auth.models import User
from companycms.widgets import AdvancedEditor
from news.models import Article
from django.db import models
class ArticleModelAdminForm(forms.ModelForm):
headline = forms.CharField(max_length=200)
content = forms.CharField(widget=AdvancedEditor())
about = forms.CharField(widget=AdvancedEditor())
pub_date = models.DateTimeField('date published')
url = forms.CharField(max_length=200)
class Meta:
model = Article
companycms/news/admin.py
from django.contrib import admin
from news.models import Article
from news.forms import ArticleModelAdminForm
class ArticleAdmin(admin.ModelAdmin):
list_display = ('headline', 'pub_date',)
form = ArticleModelAdminForm
admin.site.register(Article, ArticleAdmin)
companycms/companycms/widgets.py
from django import forms
from django.conf import settings
from django.utils.safestring import mark_safe
class AdvancedEditor(forms.Textarea):
class Media:
js = ('/static/tiny_mce/tiny_mce.js',)
def __init__(self, language=None, attrs=None):
self.language = language or settings.LANGUAGE_CODE[:2]
self.attrs = {'class': 'advancededitor'}
if attrs: self.attrs.update(attrs)
super(AdvancedEditor, self).__init__(attrs)
def render(self, name, value, attrs=None):
rendered = super(AdvancedEditor, self).render(name, value, attrs)
return rendered + mark_safe(u'''
<script type="text/javascript">
tinyMCE.init({
mode: "textareas",
theme: "advanced",
plugins: "advhr,table,emotions,media,insertdatetime,directionality",
theme_advanced_toolbar_align: "left",
theme_advanced_toolbar_location: "top",
theme_advanced_buttons1:"bold,italic,underline,strikethrough,sub,sup,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,formatselect,fontselect,fontsizeselect,forecolor",
theme_advanced_buttons2:"bullist,numlist,outdent,indent,ltr,rtl,separator,link,unlink,anchor,image,separator,table,insertdate,inserttime,advhr,emotions,media,charmap,separator,undo,redo",
theme_advanced_buttons3_add:"forecolor,backcolor",
theme_advanced_font_sizes:"170%,10px,11px,12px,13px,14px,15px,16px,17px,18px,19px,20px,21px,22px,23px,24px,25px,26px,27px,28px,29px,30px,32px,48px",
height: "350px",
width: "653px"
});
</script>''')
Having checked the JavaScript console, there are no errors being returned, and I have checked other admin pages to find that this error doesn't appear anywhere else.
Thanks in advance for your help.