Skip to content

Instantly share code, notes, and snippets.

@mhulse
Created September 18, 2011 07:52
Show Gist options
  • Select an option

  • Save mhulse/1224862 to your computer and use it in GitHub Desktop.

Select an option

Save mhulse/1224862 to your computer and use it in GitHub Desktop.
Django (1.4.0, a0) & CKEditor (3.6.2): Using Django's jQuery and CKEditor's jQuery adaptor...
# ...
# Note: I put the CKEditor package in my "static" folder.
# The below "Media" paths are relative to STATIC_URL.
# Don't forget to collectstatic for your <app_name> css/js.
class FooAdmin(admin.ModelAdmin):
form = FooForm
#...
class Media:
css = {
'all': ('<app_name>/ckeditor.css',)
}
js = ('ckeditor/ckeditor.js', 'ckeditor/adapters/jquery.js', '<app_name>/ckeditor.js',)
# ...
.cke_skin_kama {
/* Un-comment one line or the other: */
width: 85%; float: left; display: inline;
/*clear: left;*/
}
/* Using Django's instance of jQuery: */
(function($) {
$(document).ready(function() {
var config = {
toolbar:
[
['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink'],
['UIColor']
]
};
$('textarea.editor').ckeditor(config);
});
})(django.jQuery);
/* Alternatively, you can remove the outer closure and replace all instances of "$" with "django.jQuery". */
from django import forms
from <app_name>.models import *
class FooForm(forms.ModelForm):
description = forms.CharField(widget=forms.Textarea(attrs={'class':'editor'}), required=False)
class Meta:
model = Foo
@mhulse
Copy link
Copy Markdown
Author

mhulse commented Sep 18, 2011

Related links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment