[Answered ]-Use Django Flatpages with TinyMCE

1๐Ÿ‘

โœ…

I did something different, and I was missing the โ€œfieldsโ€ property in meta Class, following the new code, tested and running:

from django.contrib.flatpages.admin import FlatpageForm, FlatPageAdmin
from django.contrib import admin
from django import forms
from django.contrib.flatpages.models import FlatPage
from tinymce.widgets import TinyMCE


class FlatPageForm(forms.ModelForm):
    content = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))

    class Meta:
        model = FlatPage
        fields = '__all__'


class PageAdmin(FlatPageAdmin):
    """
    Page Admin
    """
    form = FlatPageForm


admin.site.unregister(FlatPage)
admin.site.register(FlatPage, PageAdmin)
๐Ÿ‘คLara

1๐Ÿ‘

The accepted answer wasnโ€™t working for me (Django 1.10) so this is what worked for me.

  1. I first created a new app called content in my project to keep organized.

    manage.py startapp content
    
  2. I added this to my admin.py

    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 tinymce.widgets import TinyMCE
    
    
    # Register your models here.
    class PageAdmin(FlatPageAdmin):
    """
    Page Admin
    """
    formfield_overrides = {
        models.TextField: {'widget': TinyMCE(attrs={'cols': 100, 'rows': 15})},
    }
    
    
    admin.site.unregister(FlatPage)
    admin.site.register(FlatPage, PageAdmin)
    
  3. Finally run manage.py collectstatic, restart your webserver and refresh.

๐Ÿ‘คBrett

Leave a comment