I'm currently working with the Django framework to build a content management system into a company website, and after successfully completing one page, began work on a different page that requires a rich text editor within the admin interface.
Having chosen TinyMCE for the job, I spent a lot of time on Monday trying to get it running correctly, but only managed to include a simple HTMLField(). Having been slightly confused by a number of differing tutorials, I've now encountered an error that I'm struggling to find a solution to, and one which I hoped the StackOverflow community might be able to help with.
Currently, I have the following code:
admin.py
from django.forms import *
from django.db.models import *
from tinymce.widgets import TinyMCE
from models import *
from django.contrib import admin
#class MyModelForm(forms.ModelForm):
#content = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
#class Meta:
#model = MyModel
class MyModelAdmin(admin.ModelAdmin):
form = MyModelForm
admin.site.register(MyModelForm, MyModelAdmin)
The majority of this code has been commented out for debugging purposes, as the problem seems to be with models.py:
models.py
from django import forms
from django.contrib.flatpages.models import FlatPage
from tinymce.widgets import TinyMCE
class MyModelForm(forms.ModelForm):
content = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows' : 30}))
class Meta:
model = FlatPage
This is the traceback I'm being presented with:
Environment:
Request Method: GET
Request URL: mycomputer.mydomain/company/admin/
Django Version: 1.5.1
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'cms',
'mptt',
'menus',
'south',
'sekizai',
'cms.plugins.file',
'cms.plugins.link',
'cms.plugins.picture',
'cms.plugins.text',
'reversion',
'grappelli',
'profiles',
'tinymce',
'testapp',
'django_reset')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
103. resolver_match = resolver.resolve(request.path_info)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
319. for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
347. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
342. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/home/systems/vhost-trunk/djangocms/companycms/companycms/urls.py" in <module>
7. admin.autodiscover()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/__init__.py" in autodiscover
29. import_module('%s.admin' % app)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/home/systems/vhost-trunk/djangocms/companycms/testapp/admin.py" in <module>
17. admin.site.register(MyModelForm, MyModelAdmin)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in register
77. for model in model_or_iterable:
Exception Type: TypeError at /admin/
Exception Value: 'ModelFormMetaclass' object is not iterable
As you can see, tinymce appears to be correctly installed, and the problem lies with models.ModelForm
My aim, in case it isn't clear, is to create a simple MyModel model with one content field, editable using the TinyMCE Editor. If you think I could supply any more code to shed more light on the situation, please let me know. Thanks.