diff --git a/sigi/apps/servidores/admin.py b/sigi/apps/servidores/admin.py
index 4f8faf7..303b4ce 100644
--- a/sigi/apps/servidores/admin.py
+++ b/sigi/apps/servidores/admin.py
@@ -2,6 +2,8 @@
from django.contrib import admin
from django.contrib.auth.forms import UserCreationForm
from django.contrib.contenttypes import generic
+
+from sigi.apps.utils.admin_widgets import AdminImageWidget
from sigi.apps.servidores.models import Servidor, Funcao, Licenca, Ferias
from sigi.apps.contatos.models import Endereco, Telefone
@@ -77,6 +79,13 @@ class ServidorAdmin(admin.ModelAdmin):
#}),
)
+ def formfield_for_dbfield(self, db_field, **kwargs):
+ if db_field.name == 'foto':
+ request = kwargs.pop("request", None)
+ kwargs['widget'] = AdminImageWidget
+ return db_field.formfield(**kwargs)
+ return super(ServidorAdmin,self).formfield_for_dbfield(db_field, **kwargs)
+
admin.site.register(Servidor, ServidorAdmin)
admin.site.register(Funcao, FuncaoAdmin)
admin.site.register(Ferias, FeriasAdmin)
diff --git a/sigi/apps/utils/admin_widgets.py b/sigi/apps/utils/admin_widgets.py
new file mode 100644
index 0000000..eedf837
--- /dev/null
+++ b/sigi/apps/utils/admin_widgets.py
@@ -0,0 +1,15 @@
+from django.contrib.admin.widgets import AdminFileWidget
+from django.utils.translation import ugettext as _
+from django.utils.safestring import mark_safe
+
+class AdminImageWidget(AdminFileWidget):
+ def render(self, name, value, attrs=None):
+ output = []
+ if value and getattr(value, "url", None):
+ image_url = value.url
+ file_name=str(value)
+ output.append(
+ u'
%s' % \
+ (image_url, image_url, file_name, _('Change:')))
+ output.append(super(AdminFileWidget, self).render(name, value, attrs))
+ return mark_safe(u''.join(output))