11👍
I just connect django-ckeditor to flatpages application by following code in admin.py:
from django.contrib import admin
from django.contrib.flatpages.admin import FlatPageAdmin
from django.contrib.flatpages.models import FlatPage
from django.db import models
from cked.widgets import CKEditorWidget
class FlatPageCustom(FlatPageAdmin):
formfield_overrides = {
models.TextField: {'widget': CKEditorWidget}
}
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageCustom)
It works!
0👍
from django.db.models import Field
from django.forms import Textarea
from settings import MEDIA_URL
class WidgetWYSIWYG(Textarea):
def __init__(self, *args, **kwargs):
super(WidgetWYSIWYG, self).__init__(attrs={'class': 'wysiwygEditor vLargeTextField'}, *args, **kwargs)
class Media:
js = (
MEDIA_URL+'common/tiny_mce/tiny_mce.js',
MEDIA_URL+'common/filebrowser/js/TinyMCEAdmin.js',
)
class WYSIWYGField(Field):
def get_internal_type(self):
return "TextField"
def formfield(self, **kwargs):
defaults = {'widget': WidgetWYSIWYG}
defaults.update(kwargs)
return super(WYSIWYGField, self).formfield(**defaults)
in file admin.py
from django.contrib import admin
from wysiwyg import WidgetWYSIWYG
from django.db import models
from django.contrib.flatpages.models import FlatPage
from django.contrib.flatpages.admin import FlatPageAdmin as FlatPageAdminOld
class FlatPageAdmin(FlatPageAdminOld):
formfield_overrides = {
models.TextField: {'widget': WidgetWYSIWYG},
}
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageAdmin)
- How to connect PyCharm to a Heroku postgres database
- Django's annotate Count with division returns integer instead of float
- Django dependent select
- How to get max value in django ORM
- Django-admin.py and virtualenv issue on Windows
Source:stackexchange.com