I've installed django-ckeditor on django 1.5 as instructed in the docs. I've changed TextField in my applications models.py to RichTextField as said in the docs. However I still see blank textarea in the Django admin instead of the ckeditor. This question was asked 3 years ago and none of the answers worked for me. The ckeditor.js loads just fine when I get the page. Any suggestions? my app name is newsfeed.
models.py:
from cms.models.pluginmodel import CMSPlugin
from cms.models import Page
from django.db import models
from time import time
from ckeditor.fields import RichTextField
def get_upload_file_name(instance, filename):
return "uploaded_files/%s_%s" % (str(time()).replace('.','_'),filename)
# Create your models here.
class NewsFeed (models.Model):
title = models.CharField(('Feed Name'),max_length=200,help_text=('Feed name is visible only in edit mode'))
publisher = models.CharField(('Publisher'),max_length=200)
def __unicode__(self):
return self.title
def get_absolute_url(self):
return "/newsfeed/get/%i" % self.id
class NewsItem(models.Model):
feed_id = models.ForeignKey(NewsFeed)
title = models.CharField(('Title'),max_length=200)
subtitle = models.CharField(('Sub-Title'),max_length=350,help_text=('Subtitles are displayed in auto-scroller and has max characters of 350'))
#body = models.TextField(('Content'),blank=True,help_text=('Content is NOT visible in auto-scroller !'))
body = RichTextField()
url = models.URLField(("Link"), blank=True, null=True)
page_link = models.ForeignKey(Page, verbose_name=("page"), blank=True, null=True, help_text=("A link to a page has priority over a text link."))
pub_date = models.DateTimeField('Publish Date')
is_published = models.BooleanField(('Published'), default=False)
class NewsFeedPlugin(CMSPlugin):
newsfeed = models.ForeignKey(NewsFeed)
admin.py:
from django.contrib import admin
from newsfeed.models import NewsFeed,NewsItem
from cms.admin.placeholderadmin import PlaceholderAdmin
class NewsItemInline(admin.StackedInline):
model = NewsItem
extra=0
class NewsFeedAdmin(admin.ModelAdmin):
inlines = [NewsItemInline]
class Media:
js = ('ckeditor/ckeditor/ckeditor.js')
admin.site.register(NewsFeed,NewsFeedAdmin)
config.js from ckeditor:
/**
* @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.html or http://ckeditor.com/license
*/
CKEDITOR.editorConfig = function( config ) {
// Define changes to default configuration here. For example:
// config.language = 'fr';
// config.uiColor = '#AADC6E';
};
The easiest way to do this would be by making use of
class Media
of Django'sModelAdmin
.Suppose you have an
Article
model with aTextField
to which you wish to add ckeditor. Assuming you have kept theckeditor.js
file inside your project'sstatic
folder, the following is what you should do:admin.py
That's it.
If you wish to add configuration files for ckeditor or any more JavaScript files, just do this:
In case you wish to add TinyMCE instead of ckeditor, I have a repository on GitHub to make it easier: https://github.com/xyres/django-tinymce-noapp
Update
After looking at your configuration file, I am certain the problem is not in Django but in your config file.
You need to tell CKEditor to which field to add the editor to. So, delete everything from your configuration file and add only this one line:
This would replace the textarea with an editor.
Don't forget to add this config file to the
class Media
.