-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compatibility with django-ckeditor-5 (support of the 'CKEditor5Field' field type) #576
Comments
Instead of using the CKEditor5Field in your model use the widget in your Form. If you want to use it in Django-admin override the form field in the admin.py:
Hope this answers your question. @hvlads useful to put in the readme? Happy to do so if you like :) |
To use the CKEditor5Field with django-modeltranslation, you can add it to the Take a look at the documentation here https://django-modeltranslation.readthedocs.io/en/latest/installation.html#modeltranslation-custom-fields |
Using django-ckeditor-5 in Django Admin for specific textfields.Using this approach, you don’t have to worry about modeltranslation errors related to unsupported fields. Additionally, there’s no need to add
# base_admin.py
from django.contrib import admin
from django.db import models
from django_ckeditor_5.widgets import CKEditor5Widget
class CKEditorModelAdmin(admin.ModelAdmin):
ckeditor_fields = []
def formfield_for_dbfield(self, db_field, request=None, **kwargs):
if (
isinstance(db_field, models.TextField)
and db_field.name in self.ckeditor_fields
):
kwargs["widget"] = CKEditor5Widget()
return super().formfield_for_dbfield(db_field, request, **kwargs)
# models.py
from django.db import models
class RandomModel(models.Model):
title = models.CharField(max_length=255)
description = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
# admin.py
from django.contrib import admin
from .base_admin import CKEditorModelAdmin
from .models import RandomModel
@admin.register(RandomModel)
class RandomModelAdmin(CKEditorModelAdmin):
list_display = ("title", "description", "created_at")
ckeditor_fields = ("description",) |
Hello! My website uses django-modeltranslation to support different languages. Also I want to use django-ckeditor-5 for generate rich text content. However, on trying to attach django-ckeditor-5 to my site, I got the following error:
django.core.exceptions.ImproperlyConfigured: CKEditor5Field is not supported by modeltranslation.
As I understand, the django-modeltranslation doesn't work with the field type 'CKEditor5Field'.
Is it possible to add support of CKEditor5Field field type to django-modetranslation?
The text was updated successfully, but these errors were encountered: