Thursday, September 26, 2013

django admin: integrate django-modeltranslation + django-ckeditor into 3rd party module


Hi,

I want to integrate django-modeltranslation into the cmsplugin_news package. I mean, register some fields in the News class to have a translation in the DB for each of the settings.LANGUAGES defined.


class NewNewsForm(forms.ModelForm):
    class Meta:
        model = News
        fields = ('title', 'slug', 'excerpt', 'content', 'is_published', 'pub_date')
        widgets = {
            'content': CKEditorWidget(),
            'excerpt': CKEditorWidget(),
        }

class NewNewsAdmin(TranslationAdmin):
    form = NewNewsForm

    class Media:
        js = (
            'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js',
            'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js',
            'modeltranslation/js/tabbed_translation_fields.js',
        )
        css = {
            'screen': ('modeltranslation/css/tabbed_translation_fields.css',),
        }

admin.site.register(News, NewsAdmin)

This works ok, if we just take into account django-modeltranslation. But the django-ckeditor widget is not loading. Using firebug I have seen that some static files are not loaded, so I tried loading them manually by modifying the Media class. Anyhow the editor continues not working:

class Media:
    js = (
        'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js',
        'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js',
        'modeltranslation/js/tabbed_translation_fields.js',
        'ckeditor/ckeditor/ckeditor.js',
        'ckeditor/ckeditor/config.js?t=D26D',
        'ckeditor/ckeditor/styles.js?t=D26D',
    )
    css = {
        'all': [cms_static_url(path) for path in (
            'css/rte.css',
            'css/pages.css',
            'css/change_form.css',
            'css/jquery.dialog.css',
            'css/plugin_editor.css',
        )],
        'screen': ('modeltranslation/css/tabbed_translation_fields.css',),
    }
Does anyone have any idea about how to make the editor work? Thank you very much!

Regards,

Roberto

No comments:

Post a Comment