Skip to content
This repository was archived by the owner on Feb 18, 2023. It is now read-only.

Django Integration

aleray edited this page Sep 13, 2010 · 7 revisions

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)

Installation

The Django app files are stored in the \jquery-markedit\django\markedit folder.

1. Copy the \markedit\ folder to your Python path

  • Either place it in your \Python\Lib\site-packages\ folder with Django
    - OR -
  • Place it in your project directory

2. Add ‘markedit’ to your installed apps in settings.py

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.admin',

    'markedit'
)

3. Add the markedit template folder to the template directories in settings.py

TEMPLATE_DIRS = (
    'your/project/path/markedit/templates',
)

4. Configure your markedit media path

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'

Using MarkEdit with Forms

Import the MarkEdit widget and assign it to the appropriate field.

from django import forms
from markedit.widgets import MarkEdit

class MyForm(forms.Form):
    text = forms.CharField(widget=MarkEdit)

    class Media:
        from markedit import settings
        css = getattr(settings, 'MARKEDIT_CSS', {})
        js = getattr(settings, 'MARKEDIT_JS', [])

Controlling MarkEdit options from Django

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' }
    },
})

Using MarkEdit with the Admin

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 MarkEditAdmin

class MyAdmin(MarkEditAdmin):
     # Our model has three fields:  name, description, date
     # We can specify in MarkEdit.fields which model fields to render as markedit

     class MarkEdit:
        fields = ['description', ]
        options = {
            'preview': 'above'
        }