RichTextField Support
ismailnural opened this issue · 3 comments
ismailnural commented
Hi,
Is it possible to use LocalizedTextField models with any rich text editor like ckeditor?
I'm using ckeditor for my TextField models width RichTextField() but now I cant do it and I couldn't found a way to use it.
Thanks
Photonios commented
Yes, it's possible. We do something like this:
from ckeditor.widgets import CKEditorWidget
from localized_fields.widgets import LocalizedFieldWidget
class LocalizedWYSIWYGFieldWidget(LocalizedFieldWidget):
widget = CKEditorWidget(attrs={
# These get injected in the HTML as attributes of the textarea
# and used by the ckeditor.
'data-type': 'ckeditortype',
'data-processed': '0',
'data-external-plugin-resources': '[]'
})
ppittavi commented
Thanks @Photonios ! Exactly was I looking for. Do you know how to impose a toolbar? It get Full toolbar instead the one defined in default of CKEDITOR_CONFIGS setting's variable.
ppittavi commented
finally i did it this way, let me know if someone found a better solution:
import json
from django.conf import settings
from ckeditor.widgets import CKEditorWidget
from localized_fields.widgets import LocalizedFieldWidget
class LocalizedWYSIWYGFieldWidget(AdminLocalizedFieldWidget):
widget = CKEditorWidget(
attrs={
# These get injected in the HTML as attributes of the textarea
# and used by the ckeditor.
"data-type": "ckeditortype",
"data-processed": "0",
"data-external-plugin-resources": "[]",
"data-config": json.dumps(
{
"toolbar": settings.CKEDITOR_CONFIGS["default"]["toolbar_Custom"],
}
),
}
)