LeeHanYeong / django-quill-editor

django-quill-editor makes Quill.js easy to use on Django Forms and admin sites
https://django-quill-editor.readthedocs.io
MIT License
197 stars 49 forks source link

Using Quill to edit Django flatpages? #117

Open bernd-wechner opened 1 year ago

bernd-wechner commented 1 year ago

The flatpages app is built into Django but lacks a decent editor:

https://docs.djangoproject.com/en/4.2/ref/contrib/flatpages/

I'd love to see some docs on how to attach the Quill editor to the django flatpages admin.

bernd-wechner commented 1 year ago

It's not hard as it happens, but still would be nice to see it documented as it's a common use case IMHO.

In the app's top directory, just ad admin.py if you don't have one or open it if you have one and add:

from django.contrib import admin
from django.contrib.flatpages.admin import FlatPageAdmin
from django.contrib.flatpages.models import FlatPage
from django.db import models

from django_quill.widgets import QuillWidget

class FlatPageCustom(FlatPageAdmin):
    formfield_overrides = {
        models.TextField: {'widget': QuillWidget}
    }

admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageCustom)