Fixes the size of Markdown fields in the admin, plus one other minor error #48
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 itsform_class
toMarkdownFormField
, which clobbers any attempt to override the widget. Based on the comment in the source, this was apparently done in an attempt to preventdjango.contrib.admin.ModelAdmin
from overriding the default widget. The correct way to do that is what has already been implemented in this project – usingformfield_overrides
in a subclass ofModelAdmin
. 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 variablejQuery
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 runningmarkItUp
using a selector injquery.init.js
. Since we still needextra_settings
I changed it to simply set it as a global variable namedextra_markitup_settings
, since it'll have the same value for each field.I also removed the
__init__
method fromMarkdownWidget
, since all it wasn't actually doing anything that wouldn't happen if it didn't exist.