Created
September 18, 2011 07:52
-
-
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...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ... | |
| # 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',) | |
| # ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .cke_skin_kama { | |
| /* Un-comment one line or the other: */ | |
| width: 85%; float: left; display: inline; | |
| /*clear: left;*/ | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 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". */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related links: