I'm building a blog, with models "Post" and "Image" like so:
class Post(models.Model):
title = models.CharField(max_length=1000)
author = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
text = models.TextField(max_length=10000)
class Image(models.Model):
post = models.ForeignKey(Post, related_name='images')
image = models.ImageField(upload_to='photos/%Y/%m/%d')
caption = models.CharField(max_length=1000,blank=True)
I've been trying to implement the Dojo rich editor in my admin site by following the example here:
http://lazutkin.com/blog/2011/mar/13/using-dojo-rich-editor-djangos-admin/
However, there's some kind of interference between settings in my admin.py file that is keeping me from registering both the rich editor and a ModelAdmin class for uploading images associated with an instance of "Post." If I use the following code in my admin.py file:
from django.contrib.admin import site, ModelAdmin
import models
class CommonMedia:
js = (
'https://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js',
'editor.js',
)
css = {
'all': ('editor.css',),
}
site.register(models.Post,
Media = CommonMedia,
)
The rich text editor shows up fine. But if I add some code for image uploading fields, like so:
from blogs.models import Post,Image
from django.contrib import admin
from django.contrib.admin import site, ModelAdmin
import models
class CommonMedia:
js = (
'https://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js',
'editor.js',
)
css = {
'all': ('editor.css',),
}
class PostImageInline(admin.TabularInline):
model = Image
extra = 5
class PostAdmin(admin.ModelAdmin):
inlines = [PostImageInline]
site.register(models.Post,
list_display = ('text',),
search_fields = ['text',],
Media = CommonMedia,
)
admin.site.unregister(Post)
admin.site.register(Post, PostAdmin)
the rich editor doesn't show up. I'm guessing this is due to the "admin.site.unregister(Post)" line, but if I don't use that I get the error, "The model Post is already registered." If instead I remove both that line and the "Post" from "admin.site.register(Post, PostAdmin)", I get the error: "'MediaDefiningClass' object is not iterable". I know I must be going about registering my ModelAdmin and the rich editor incorrectly, but I can't seem to find any documentation online about "admin.site.register" and "site.register," so I'm totally stuck. Any help on this would be much appreciated!
cheers,
Guillaume