Search code examples
pythondjangockeditor

RichTextUploadingField not reflecting to models


So I have been following the step by step from this website to integrating-ckeditor-in-django but it is not reading/ reflecting in my models.py

Here is the step by step that I have followed:

Step 1:

pip install django-ckeditor

Step 2:

INSTALLED_APPS = [
    'ckeditor',
    'ckeditor_uploader',
    ..................]

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
CRISPY_TEMPLATE_PACK = 'bootstrap4'

#...
SITE_ID = 1

####################################
    ##  CKEDITOR CONFIGURATION ##
####################################

CKEDITOR_JQUERY_URL = 'https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js'

CKEDITOR_UPLOAD_PATH = 'uploads/'
CKEDITOR_IMAGE_BACKEND = "pillow"

CKEDITOR_CONFIGS = {
    'default': {
        'toolbar': None,
    },
}

###################################

Step 3: in the main projects folder urls.py:

    path('ckeditor/', include('ckeditor_uploader.urls')),

in the models.py

from ckeditor_uploader.fields import RichTextField, RichTextUploadingField

class ModelClass:
    ## content = models.TextField()
    content = RichTextUploadingField()

It is getting an error when migrating

ImportError: cannot import name 'RichTextField' from 'ckeditor_uploader.fields' (C:\Users\User\Desktop\Project\venv\lib\site-packages\ckeditor_uploader\fields.py)

What am I missing?


Solution

  • The RichTextUploadingField belongs to from ckeditor_uploader.fields import RichTextUploadingField, but the RichTextField to the ckeditor.fields. You thus import these with:

    from ckeditor.fields import RichTextField
    from ckeditor_uploader.fields import RichTextUploadingField

    In your question you do not use the RichTextUploadingField, so in that case you can remove the second import.