WMD in Django Admin?
Asked Answered
S

4

10

I know how to use WMD and other such javascript editors in regular django forms using widget=. However, how do I use WMD for text fields in the Django admin? On top of that, how do I use it for the content field on contrib.flatpages in the admin?

Also, I think I might like to use the StackOverflow fork of WMD, so I would like any special instructions for that, if necessary.

I know how to use the markdown filter in the templates, so that part is ok. I just need to get the editor to show up and work in the admin interface.

Sonometer answered 11/8, 2009 at 2:2 Comment(0)
S
5

I gave up on trying to use WMD. Instead, I used Markitup! As of the time of this posting, the current version of WMD is just not up to snuff. The StackOverflow fork of it is better, but is missing many features I want.

Instead, I decided to use Markitup! It has a Django reusable app. It also integrates very well with the existing django.contrib.markup template filters.

django-markitup

I also found a site that shows how to use it for flatpages without having to edit the admin templates.

extending admin forms in django

Sonometer answered 12/8, 2009 at 14:38 Comment(2)
That's too bad, because we've created django-wmd-editor: github.com/scrum8/django-wmd-editorLineolate
It wasn't out at the time I needed it.Sonometer
P
2

To insert WMD, or any other cool JS, into the Django Admin pages, follow the instructions on overriding the admin templates in the Django docs, right here -- worst case, you'll copy and edit the existing Django templates to add your required JS functionality, and use those instructions to make sure your modified templates are used instead of Django's default ones, but almost always you can do better than this, as you'll see in those instructions.

Procora answered 11/8, 2009 at 2:50 Comment(0)
J
1

This isn't a direct answer to your question, but it might help.

It seems to be quite common to add the TinyMCE WYSIWYG editor to django. If you search for instructions on how to add TinyMCE to the Django admin, you might be able to adapt the method for WMD.

In the book Practical Django Projects, Second Edition, the author embeds TinyMCE in the flatpages admin. You can download the code from a Bitbucket repository, and see how it's done (look at cms/templates/admin/). Alternatively, you could try this guide on the Django website.


+1 for the question. I would also like to write flatpages in markdown. However I think the best method for using markdown is to

  1. have two fields, say content and content_html, and store the original markdown in content.
  2. When the object is saved, convert the markdown to html and store it in content_html.

This means you avoid converting to html in the template every time the page is viewed. However I don't know an elegant way to extend contrib.flatpages by 'adding' an extra field.

Johns answered 11/8, 2009 at 2:45 Comment(1)
Oh wow, that's a really clever idea, having two fields. Obviously the HTML field would be non-editable. However, I think you could also just cache the converted HTML, and achieve almost the same benefits performance-wise.Sonometer
B
0

Check this one http://fi.am/entry/adding-a-simple-wysiwym-markdown-editor-to-your-mo/

This is much better solution.

So simple, and clear.

Benue answered 3/2, 2010 at 10:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.