-
Notifications
You must be signed in to change notification settings - Fork 11
Django Integration
MarkEdit provides a Django app to provide easy integration for MarkEdit use in either Django Forms or Admin.
MarkEdit in the Admin (running under Grappelli)
The Django app files are stored in the \jquery-markedit\django\markedit folder.
- Either place it in your \Python\Lib\site-packages\ folder with Django
- OR - - Place it in your project directory
INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.admin','markedit' )
TEMPLATE_DIRS = (
'your/project/path/markedit/templates',
)By default, markedit assumes it knows where the media files for jquery-markedit exist, however, it’s assumption may not be correct, especially if you’ve installed jquery-markedit to another location.
Open project\markedit\settings.py and examine the paths. The default path is:
MEDIA_URL + /js/jquery-markedit/jquery.markedit.js'Import the MarkEdit widget and assign it to the appropriate field.
from django import forms from markedit.widgets import MarkEditclass MyForm(forms.Form): text = forms.CharField(widget=MarkEdit)class Media: from markedit import settings css = getattr(settings, 'MARKEDIT_CSS', {}) js = getattr(settings, 'MARKEDIT_JS', [])
The MarkEdit widget will let you pass options as a widget attribute. It is possible to configure all text values from Python.
text = forms.CharField( widget = MarkEdit ( attrs = {
'options': {
'preview' : 'below'
'toolbar': { 'backgroundMode' : 'dark' }
},
})In addition to manually overriding the Form (similar to above), MarkEdit provides an Admin class that can be inherited to quickly provide MarkEdit integration. Once inherited, an inner class ‘MarkEdit’ can be used to indicate which fields are to be to be rendered as a jquery-markedit editor.
from markedit.admin import MarkEditAdminclass MyAdmin(MarkEditAdmin): # Our model has three fields: name, description, date # We can specify in MarkEdit.fields which model fields to render as markeditclass MarkEdit: fields = ['description', ] options = { 'preview': 'above' }
