Code above was a bit incorrect. Here better solution:
## widget declaration
from django.utils.safestring import mark_safe
from django.forms.widgets import FileInput
class AdminImageFieldWithThumbWidget(FileInput):
def __init__(self, thumb_width=50, thumb_height=50):
self.width = thumb_width
self.height = thumb_height
super(AdminImageFieldWithThumbWidget, self).__init__({})
def render(self, name, value, attrs=None):
thumb_html = ''
if value and hasattr(value, "url"):
thumb_html = '<img src="%s" width="%s" width="%s"/>' %
(value.url, self.width, self.height)
return mark_safe("%s%s" % (thumb_html,
super(AdminImageFieldWithThumbWidget, self).render(name, value,
attrs)))
##form sample
class PhotoBaseInline(admin.StackedInline):
fieldsets = (
(None, {'fields': (('photo', 'default'),)}),
)
thumb_width = 50
thumb_height = 50
def formfield_for_dbfield(self, db_field, **kwargs):
field =
super(PhotoBaseInline,self).formfield_for_dbfield(db_field,**kwargs)
if db_field.name == 'photo':
return
forms.ImageField(widget=AdminImageFieldWithThumbWidget(thumb_width=self.thumb_width,
thumb_height=self.thumb_height))
return field
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---