django_markdown
django_markdown copied to clipboard
Fixes the size of Markdown fields in the admin, plus one other minor error
The main issue I fixed is that in the admin the Markdown textareas were very narrow, and there was no way to fix it from an application (without monkey patching). The issue was due to the fact that MarkdownField
explicitly sets its form_class
to MarkdownFormField
, which clobbers any attempt to override the widget. Based on the comment in the source, this was apparently done in an attempt to prevent django.contrib.admin.ModelAdmin
from overriding the default widget. The correct way to do that is what has already been implemented in this project – using formfield_overrides
in a subclass of ModelAdmin
. So, since the problem is already solved in the correct way, I'm pretty sure I'm more or less just reverting it to an earlier behavior.
The other issue this pull request fixes is an issue when using a Markdown field on the frontend results in a JS error when JS files are included at the bottom of the body (which is a best practice). The closures in editor_init.html
explicitly reference the variable jQuery
in the global scope, but since jquery isn't included until later, the variable doesn't yet exist. My fix actually simplifies the code quite a bit by identifying the markdown elements using a "widget" custom data attribute, then running markItUp
using a selector in jquery.init.js
. Since we still need extra_settings
I changed it to simply set it as a global variable named extra_markitup_settings
, since it'll have the same value for each field.
I also removed the __init__
method from MarkdownWidget
, since all it wasn't actually doing anything that wouldn't happen if it didn't exist.