Skip to content
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

无法支持RichTextUploadingField #733

Open
Ekre1c opened this issue May 29, 2022 · 1 comment
Open

无法支持RichTextUploadingField #733

Ekre1c opened this issue May 29, 2022 · 1 comment

Comments

@Ekre1c
Copy link

Ekre1c commented May 29, 2022

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

@ljluestc
Copy link

确保您已正确安装了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中显示富文本编辑器

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants