Skip to content

A django app that allows the easy addition of Stack Overflow's "PageDown" markdown editor to a django form field, whether in a custom app or the Django Admin

License

Notifications You must be signed in to change notification settings

gandalf013/django-pagedown

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django Pagedown

A django app that allows the easy addition of Stack Overflow's "Pagedown" Markdown editor to a django form field, whether in a custom app or the Django Admin


Screenshot of Django Admin with Pagedown initialised


Installation

  1. Get the code: pip install django-pagedown
  2. Add pagedown to your INSTALLED_APPS
  3. Make sure to collect the static files: python manage.py collectstatic --noinput

Note that this package will install a cloned copy (git submodule)of the Pagedown library from http://github.com/timmyomahony/pagedown/.

If you don't like (or are having problems with) PyPi, you can alternatively install:

  • Via pip from GitHub: pip install -e https://timmyomahony@github.com/timmyomahony/django-pagedown.git#egg=django-pagedown
  • Manually clone from Github:
    • git clone https://timmyomahony@github.com/timmyomahony/django-pagedown.git
    • cd django-pagedown
    • git submodule update --init

Usage

If you want to use the pagedown editor in a django admin field, there are numerous possible approaches:

To use it in all TextField's in you admin form:

from pagedown.widgets import AdminPagedownWidget
from django.db import models


class FooModelAdmin(models.ModelAdmin):
	formfield_overrides = {
    	models.TextField: {'widget': AdminPagedownWidget },
	}

Alternatively, to only use it on particular fields, first create a form (in forms.py):

from pagedown.widgets import AdminPagedownWidget 
from django import forms
from models import FooModel


class FooModelForm(forms.ModelForm):
    a_text_field = forms.CharField(widget=AdminPagedownWidget())		
    another_text_field = forms.CharField(widget=AdminPagedownWidget())	
	
class Meta:
    model = FooModel

and in your admin.py:

from forms import FooModelForm
from models import FooModel
from django.contrib import admin


class FooModelAdmin(admin.ModelAdmin):
	form = FooModelForm   
	
admin.site.register(FooModel, FooModelAdmin)

Notes

  • There are two widgets, AdminPageDownWidget and PageDownWidget. The only difference is that AdminPageDownWidget includes extra CSS to make the preview area and input pretty in the django admin. If you are using the editor for your own app, you will need to supply CSS to do this.

About

A django app that allows the easy addition of Stack Overflow's "PageDown" markdown editor to a django form field, whether in a custom app or the Django Admin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 50.7%
  • CSS 49.3%