djangodjango-admintinymcedjango-flatpagesdjango-tinymce

Use Django Flatpages with TinyMCE


I'm trying to achive the Django TinyMCE widget with Django Flatpages (into Admin).

I already read this Embedding tinyMCE in django flatpage

I did the sabe but is not working. Here is my admin.py code:

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


class PageForm(FlatpageForm):

    class Meta:
        model = FlatPage
        widgets = {
            'content': TinyMCE(attrs={'cols': 100, 'rows': 15}),
        }


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

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

My site is running well, without erros, is possible to edit or create a new Django Flatpage but the widget doesn't appear. Any ideas?


Solution

  • 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)