Django: What's an awesome plugin to maintain images in the admin?
Posted
by meder
on Stack Overflow
See other posts from Stack Overflow
or by meder
Published on 2010-02-07T23:04:40Z
Indexed on
2010/03/17
13:31 UTC
Read the original article
Hit count: 769
I have an articles entry model and I have an excerpt and description field. If a user wants to post an image then I have a separate ImageField which has the default standard file browser.
I've tried using django-filebrowser
but I don't like the fact that it requires django-grappelli
nor do I necessarily want a flash upload utility - can anyone recommend a tool where I can manage image uploads, and basically replace the file browse provided by django with an imagepicking browser?
In the future I'd probably want it to handle image resizing and specify default image sizes for certain article types.
Edit: I'm trying out adminfiles now but I'm having issues installing it. I grabbed it and added it to my python path, added it to INSTALLED_APPS, created the databases for it, uploaded an image. I followed the instructions to modify my Model to specify adminfiles_fields
and registered but it's not applying in my admin, here's my admin.py
for articles:
from django.contrib import admin
from django import forms
from articles.models import Category, Entry
from tinymce.widgets import TinyMCE
from adminfiles.admin import FilePickerAdmin
class EntryForm( forms.ModelForm ):
class Media:
js = ['/media/tinymce/tiny_mce.js', '/media/tinymce/load.js']#, '/media/admin/filebrowser/js/TinyMCEAdmin.js']
class Meta:
model = Entry
class CategoryAdmin(admin.ModelAdmin):
prepopulated_fields = { 'slug': ['title'] }
class EntryAdmin( FilePickerAdmin ):
adminfiles_fields = ('excerpt',)
prepopulated_fields = { 'slug': ['title'] }
form = EntryForm
admin.site.register( Category, CategoryAdmin )
admin.site.register( Entry, EntryAdmin )
Here's my Entry model:
class Entry( models.Model ):
LIVE_STATUS = 1
DRAFT_STATUS = 2
HIDDEN_STATUS = 3
STATUS_CHOICES = (
( LIVE_STATUS, 'Live' ),
( DRAFT_STATUS, 'Draft' ),
( HIDDEN_STATUS, 'Hidden' ),
)
status = models.IntegerField( choices=STATUS_CHOICES, default=LIVE_STATUS )
tags = TagField()
categories = models.ManyToManyField( Category )
title = models.CharField( max_length=250 )
excerpt = models.TextField( blank=True )
excerpt_html = models.TextField(editable=False, blank=True)
body_html = models.TextField( editable=False, blank=True )
article_image = models.ImageField(blank=True, upload_to='upload')
body = models.TextField()
enable_comments = models.BooleanField(default=True)
pub_date = models.DateTimeField(default=datetime.datetime.now)
slug = models.SlugField(unique_for_date='pub_date')
author = models.ForeignKey(User)
featured = models.BooleanField(default=False)
def save( self, force_insert=False, force_update= False):
self.body_html = markdown(self.body)
if self.excerpt:
self.excerpt_html = markdown( self.excerpt )
super( Entry, self ).save( force_insert, force_update )
class Meta:
ordering = ['-pub_date']
verbose_name_plural = "Entries"
def __unicode__(self):
return self.title
Edit #2: To clarify I did move the media files to my media path and they are indeed rendering the image area, I can upload fine, the <<<image>>>
tag is inserted into my editable MarkItUp w/ Markdown area but it isn't rendering in the MarkItUp preview - perhaps I just need to apply the |upload_tags
into that preview. I'll try adding it to my template which posts the article as well.
© Stack Overflow or respective owner