diff options
Diffstat (limited to 'ishtar_common/widgets.py')
-rw-r--r-- | ishtar_common/widgets.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index 60e5fc016..192de6f65 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -25,6 +25,7 @@ from django import forms from django.conf import settings from django.core.urlresolvers import reverse, NoReverseMatch from django.db.models import fields +from django.db.models.fields.files import ImageFieldFile from django.forms import ClearableFileInput from django.forms.utils import flatatt from django.forms.widgets import CheckboxSelectMultiple as \ @@ -294,6 +295,17 @@ class ImageFileInput(ClearableFileInput): template_name = 'widgets/image_input.html' NO_FORM_CONTROL = True + def format_value(self, value): + if self.is_initial(value): + return value + # try to display posted images + if hasattr(value, 'file'): + full_path = unicode(value.file) + if full_path.startswith(settings.MEDIA_ROOT): + value.url = settings.MEDIA_URL + full_path[ + len(settings.MEDIA_ROOT):] + return value + class SquareMeterWidget(forms.TextInput): def render(self, name, value, attrs=None, renderer=None): |