Ticket #5476: image-preview-in-admin.diff
File image-preview-in-admin.diff, 2.6 KB (added by , 16 years ago) |
---|
-
django/db/models/fields/__init__.py
901 901 return super(FloatField, self).formfield(**defaults) 902 902 903 903 class ImageField(FileField): 904 def __init__(self, verbose_name=None, name=None, width_field=None, height_field=None, **kwargs):904 def __init__(self, verbose_name=None, name=None, width_field=None, height_field=None, admin_preview=False, **kwargs): 905 905 self.width_field, self.height_field = width_field, height_field 906 self.admin_preview = admin_preview 906 907 FileField.__init__(self, verbose_name, name, **kwargs) 907 908 908 909 def get_manipulator_field_objs(self): -
django/contrib/admin/options.py
173 173 return db_field.formfield(**kwargs) 174 174 175 175 # For FileFields and ImageFields add a link to the current file. 176 if isinstance(db_field, models.ImageField) or isinstance(db_field, models.FileField): 176 if isinstance(db_field, models.ImageField): 177 if db_field.admin_preview: 178 kwargs['widget'] = widgets.AdminImageWidget 179 else: 180 kwargs['widget'] = widgets.AdminFileWidget 181 return db_field.formfield(**kwargs) 182 elif isinstance(db_field, models.ImageField) or isinstance(db_field, models.FileField): 177 183 kwargs['widget'] = widgets.AdminFileWidget 178 184 return db_field.formfield(**kwargs) 179 185 -
django/contrib/admin/widgets.py
93 93 output.append(super(AdminFileWidget, self).render(name, value, attrs)) 94 94 return mark_safe(u''.join(output)) 95 95 96 class AdminImageWidget(AdminFileWidget): 97 """ 98 Just like AdminFileWidget but adds image to admin page. 99 """ 100 def render(self, name, value, attrs=None): 101 from django.conf import settings 102 output = [] 103 if value: 104 output.append('<img src="%s%s" /> <br />' % (settings.MEDIA_URL, value)) 105 output.append(super(AdminImageWidget, self).render(name, value, attrs)) 106 return mark_safe(u''.join(output)) 107 108 96 109 class ForeignKeyRawIdWidget(forms.TextInput): 97 110 """ 98 111 A Widget for displaying ForeignKeys in the "raw_id" interface rather than