sshwsfc / xadmin

Drop-in replacement of Django admin comes with lots of goodies, fully extensible with plugin support, pretty UI based on Twitter Bootstrap.
http://www.xadmin.io
BSD 3-Clause "New" or "Revised" License
4.76k stars 1.41k forks source link

无法支持RichTextUploadingField #733

Open Ekre1c opened 2 years ago

Ekre1c commented 2 years ago

Django版本3.2.13 xadmin版本2.0.1 django-ckeditor版本6.3.2 当将模型类字段类型改成RichTextField时xadmin能够显示富文本编辑 当将模型类字段类型改成RichTextUploadingField时xadmin则无法显示富文本编辑

ljluestc commented 1 year ago

确保您已正确安装了django-ckeditor库,并且在INSTALLED_APPS设置中添加了ckeditor。 确保您在模型类中正确导入了所需的字段类型和相关模块。例如,您的模型类应该包含以下导入语句:

from ckeditor.fields import RichTextField, RichTextUploadingField 针对RichTextUploadingField字段类型,您可以尝试进行一些自定义配置,以使其在xadmin中正常显示富文本编辑器。在您的xadmin的ModelAdmin类中,您可以通过重写formfield_for_dbfield方法来指定字段的表单小部件。例如:

from xadmin import views from ckeditor.widgets import CKEditorWidget

class MyModelAdmin(views.CommAdminView): def formfield_for_dbfield(self, db_field, kwargs): if isinstance(db_field, RichTextUploadingField): kwargs['widget'] = CKEditorWidget() return super().formfield_for_dbfield(db_field, kwargs) 这将使用CKEditorWidget作为RichTextUploadingField字段类型的表单小部件,以便在xadmin中显示富文本编辑器